From e09147417d2f6456202376d1ba44695e4ebf58a6 Mon Sep 17 00:00:00 2001 From: Chris King <kingtc@uab.edu> Date: Tue, 26 Apr 2022 14:32:42 +0000 Subject: [PATCH] Move static node setup to a role in preparation for a gpu node --- ansible/node.yml | 134 +------------------- ansible/roles/cheaha.node/.travis.yml | 29 +++++ ansible/roles/cheaha.node/README.md | 38 ++++++ ansible/roles/cheaha.node/defaults/main.yml | 2 + ansible/roles/cheaha.node/handlers/main.yml | 2 + ansible/roles/cheaha.node/meta/main.yml | 52 ++++++++ ansible/roles/cheaha.node/tasks/main.yml | 130 +++++++++++++++++++ ansible/roles/cheaha.node/tests/inventory | 2 + ansible/roles/cheaha.node/tests/test.yml | 5 + ansible/roles/cheaha.node/vars/main.yml | 2 + openstack/nodeimage.pkr.hcl | 1 + 11 files changed, 265 insertions(+), 132 deletions(-) create mode 100644 ansible/roles/cheaha.node/.travis.yml create mode 100644 ansible/roles/cheaha.node/README.md create mode 100644 ansible/roles/cheaha.node/defaults/main.yml create mode 100644 ansible/roles/cheaha.node/handlers/main.yml create mode 100644 ansible/roles/cheaha.node/meta/main.yml create mode 100644 ansible/roles/cheaha.node/tasks/main.yml create mode 100644 ansible/roles/cheaha.node/tests/inventory create mode 100644 ansible/roles/cheaha.node/tests/test.yml create mode 100644 ansible/roles/cheaha.node/vars/main.yml diff --git a/ansible/node.yml b/ansible/node.yml index c76b148..77d1c96 100644 --- a/ansible/node.yml +++ b/ansible/node.yml @@ -2,135 +2,5 @@ - name: Setup node for use as a cluster host hosts: default become: true - - tasks: - - name: Update /etc/hosts with cluster addressing - ansible.builtin.lineinfile: - path: /etc/hosts - line: "{{ item }}" - loop: - - "172.20.0.24 cheaha-master02.cm.cluster cheaha-master02" - - "172.20.0.22 cheaha-master01.cm.cluster cheaha-master01" - - "172.20.0.25 master.cm.cluster master localmaster.cm.cluster localmaster ldapserver.cm.cluster ldapserver" - - name: Install prerequisite packages - yum: - name: epel-release - state: present - - name: Disable SELinux - ansible.posix.selinux: - state: disabled - - name: Copy cm.repo into place (consider making this a template) - ansible.builtin.copy: - src: cm.repo - dest: /etc/yum.repos.d/cm.repo - owner: root - group: root - mode: 0644 - - name: Copy CM repo GPG key - ansible.builtin.copy: - src: RPM-GPG-KEY-cm - dest: /etc/pki/rpm-gpg/RPM-GPG-KEY-cm - owner: root - group: root - mode: 0644 - - name: Create slurm group - ansible.builtin.group: - name: slurm - state: present - gid: 450 - - name: Create slurm user - ansible.builtin.user: - name: slurm - state: present - uid: 450 - group: slurm - - name: Install required packages - yum: - name: - - slurm-client-18.08.9-100463_cm8.2_a522576834.x86_64 - - munge-0.5.13-139_cm8.2.x86_64 - - openldap-servers-2.4.48-290_cm8.2 - - Lmod-7.7.14-100054_cm8.2_4cb5624f0b.noarch - - cm-modules-init-client-8.2-70_cm8.2.noarch - - cmdaemon - - nss-pam-ldapd - - openldap-servers - state: present - - name: Update nsswitch.conf to look for ldap - ansible.builtin.replace: - dest: /etc/nsswitch.conf - regexp: '^({{ item }}:(?!.*\bldap\b).*)$' - replace: '\1 ldap' - loop: - - passwd - - shadow - - group - - netgroup - - automount - - name: Set up NFS GPFS mount point(s) - ansible.posix.mount: - path: "{{ item.path }}" - src: "{{ item.src }}" - fstype: "{{ item.fstype }}" - opts: "{{ item.opts }}" - state: present - loop: - - { path: /cm/shared, src: "gpfs.rc.uab.edu:/data/cm/shared-8.2", fstype: nfs, opts: _netdev,defaults } - - { path: /home, src: "gpfs.rc.uab.edu:/data/user/home", fstype: nfs, opts: _netdev,defaults } - - { path: /data/project, src: "gpfs.rc.uab.edu:/data/project", fstype: nfs, opts: _netdev,defaults } - - { path: /data/user, src: "gpfs.rc.uab.edu:/data/user", fstype: nfs, opts: _netdev,defaults } - - name: Add ssh key for root access - ansible.posix.authorized_key: - user: root - state: present - key: "{{ root_ssh_key }}" - - name: Copy munge key - ansible.builtin.copy: - src: munge.key - dest: /etc/munge/munge.key - owner: daemon - group: root - mode: 0400 - - name: Copy ldap cert(s) into place - ansible.builtin.copy: - src: "{{ item.src }}" - dest: "/cm/local/apps/openldap/etc/certs/{{ item.src }}" - owner: ldap - group: ldap - mode: 0440 - loop: - - { src: ca.pem } - - { src: ldap.key } - - { src: ldap.pem } - - name: Copy ldap config into place - ansible.builtin.copy: - src: nslcd.conf - dest: /etc/nslcd.conf - owner: root - group: root - mode: 0600 - - name: Enable services - ansible.builtin.service: - name: "{{ item }}" - enabled: yes - loop: - - munge - - slurmd - - nslcd - - name: Create base directories - ansible.builtin.file: - path: "{{ item.dir }}" - state: directory - mode: "{{ item.mode }}" - loop: - - { dir: /local, mode: '0777' } - - { dir: /scratch, mode: '0755' } - - name: Create symbolic link from /scratch/local to /local - ansible.builtin.file: - src: /local - dest: /scratch/local - owner: root - group: root - state: link - - + roles: + - cheaha.node diff --git a/ansible/roles/cheaha.node/.travis.yml b/ansible/roles/cheaha.node/.travis.yml new file mode 100644 index 0000000..36bbf62 --- /dev/null +++ b/ansible/roles/cheaha.node/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "2.7" + +# Use the new container infrastructure +sudo: false + +# Install ansible +addons: + apt: + packages: + - python-pip + +install: + # Install ansible + - pip install ansible + + # Check ansible version + - ansible --version + + # Create ansible.cfg with correct roles_path + - printf '[defaults]\nroles_path=../' >ansible.cfg + +script: + # Basic role syntax check + - ansible-playbook tests/test.yml -i tests/inventory --syntax-check + +notifications: + webhooks: https://galaxy.ansible.com/api/v1/notifications/ \ No newline at end of file diff --git a/ansible/roles/cheaha.node/README.md b/ansible/roles/cheaha.node/README.md new file mode 100644 index 0000000..225dd44 --- /dev/null +++ b/ansible/roles/cheaha.node/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/ansible/roles/cheaha.node/defaults/main.yml b/ansible/roles/cheaha.node/defaults/main.yml new file mode 100644 index 0000000..9832282 --- /dev/null +++ b/ansible/roles/cheaha.node/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for cheaha.node diff --git a/ansible/roles/cheaha.node/handlers/main.yml b/ansible/roles/cheaha.node/handlers/main.yml new file mode 100644 index 0000000..78a66c4 --- /dev/null +++ b/ansible/roles/cheaha.node/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for cheaha.node diff --git a/ansible/roles/cheaha.node/meta/main.yml b/ansible/roles/cheaha.node/meta/main.yml new file mode 100644 index 0000000..c572acc --- /dev/null +++ b/ansible/roles/cheaha.node/meta/main.yml @@ -0,0 +1,52 @@ +galaxy_info: + author: your name + description: your role description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Choose a valid license ID from https://spdx.org - some suggested licenses: + # - BSD-3-Clause (default) + # - MIT + # - GPL-2.0-or-later + # - GPL-3.0-only + # - Apache-2.0 + # - CC-BY-4.0 + license: license (GPL-2.0-or-later, MIT, etc) + + min_ansible_version: 2.1 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: [] + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. diff --git a/ansible/roles/cheaha.node/tasks/main.yml b/ansible/roles/cheaha.node/tasks/main.yml new file mode 100644 index 0000000..9397ba9 --- /dev/null +++ b/ansible/roles/cheaha.node/tasks/main.yml @@ -0,0 +1,130 @@ +--- +# tasks file for cheaha.node +- name: Update /etc/hosts with cluster addressing + ansible.builtin.lineinfile: + path: /etc/hosts + line: "{{ item }}" + loop: + - "172.20.0.24 cheaha-master02.cm.cluster cheaha-master02" + - "172.20.0.22 cheaha-master01.cm.cluster cheaha-master01" + - "172.20.0.25 master.cm.cluster master localmaster.cm.cluster localmaster ldapserver.cm.cluster ldapserver" +- name: Install prerequisite packages + yum: + name: epel-release + state: present +- name: Disable SELinux + ansible.posix.selinux: + state: disabled +- name: Copy cm.repo into place (consider making this a template) + ansible.builtin.copy: + src: cm.repo + dest: /etc/yum.repos.d/cm.repo + owner: root + group: root + mode: 0644 +- name: Copy CM repo GPG key + ansible.builtin.copy: + src: RPM-GPG-KEY-cm + dest: /etc/pki/rpm-gpg/RPM-GPG-KEY-cm + owner: root + group: root + mode: 0644 +- name: Create slurm group + ansible.builtin.group: + name: slurm + state: present + gid: 450 +- name: Create slurm user + ansible.builtin.user: + name: slurm + state: present + uid: 450 + group: slurm +- name: Install required packages + yum: + name: + - slurm-client-18.08.9-100463_cm8.2_a522576834.x86_64 + - munge-0.5.13-139_cm8.2.x86_64 + - openldap-servers-2.4.48-290_cm8.2 + - Lmod-7.7.14-100054_cm8.2_4cb5624f0b.noarch + - cm-modules-init-client-8.2-70_cm8.2.noarch + - cmdaemon + - nss-pam-ldapd + - openldap-servers + state: present +- name: Update nsswitch.conf to look for ldap + ansible.builtin.replace: + dest: /etc/nsswitch.conf + regexp: '^({{ item }}:(?!.*\bldap\b).*)$' + replace: '\1 ldap' + loop: + - passwd + - shadow + - group + - netgroup + - automount +- name: Set up NFS GPFS mount point(s) + ansible.posix.mount: + path: "{{ item.path }}" + src: "{{ item.src }}" + fstype: "{{ item.fstype }}" + opts: "{{ item.opts }}" + state: present + loop: + - { path: /cm/shared, src: "gpfs.rc.uab.edu:/data/cm/shared-8.2", fstype: nfs, opts: _netdev,defaults } + - { path: /home, src: "gpfs.rc.uab.edu:/data/user/home", fstype: nfs, opts: _netdev,defaults } + - { path: /data/project, src: "gpfs.rc.uab.edu:/data/project", fstype: nfs, opts: _netdev,defaults } + - { path: /data/user, src: "gpfs.rc.uab.edu:/data/user", fstype: nfs, opts: _netdev,defaults } +- name: Add ssh key for root access + ansible.posix.authorized_key: + user: root + state: present + key: "{{ root_ssh_key }}" +- name: Copy munge key + ansible.builtin.copy: + src: munge.key + dest: /etc/munge/munge.key + owner: daemon + group: root + mode: 0400 +- name: Copy ldap cert(s) into place + ansible.builtin.copy: + src: "{{ item.src }}" + dest: "/cm/local/apps/openldap/etc/certs/{{ item.src }}" + owner: ldap + group: ldap + mode: 0440 + loop: + - { src: ca.pem } + - { src: ldap.key } + - { src: ldap.pem } +- name: Copy ldap config into place + ansible.builtin.copy: + src: nslcd.conf + dest: /etc/nslcd.conf + owner: root + group: root + mode: 0600 +- name: Enable services + ansible.builtin.service: + name: "{{ item }}" + enabled: yes + loop: + - munge + - slurmd + - nslcd +- name: Create base directories + ansible.builtin.file: + path: "{{ item.dir }}" + state: directory + mode: "{{ item.mode }}" + loop: + - { dir: /local, mode: '0777' } + - { dir: /scratch, mode: '0755' } +- name: Create symbolic link from /scratch/local to /local + ansible.builtin.file: + src: /local + dest: /scratch/local + owner: root + group: root + state: link diff --git a/ansible/roles/cheaha.node/tests/inventory b/ansible/roles/cheaha.node/tests/inventory new file mode 100644 index 0000000..878877b --- /dev/null +++ b/ansible/roles/cheaha.node/tests/inventory @@ -0,0 +1,2 @@ +localhost + diff --git a/ansible/roles/cheaha.node/tests/test.yml b/ansible/roles/cheaha.node/tests/test.yml new file mode 100644 index 0000000..47dc190 --- /dev/null +++ b/ansible/roles/cheaha.node/tests/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: localhost + remote_user: root + roles: + - cheaha.node diff --git a/ansible/roles/cheaha.node/vars/main.yml b/ansible/roles/cheaha.node/vars/main.yml new file mode 100644 index 0000000..d6c81c2 --- /dev/null +++ b/ansible/roles/cheaha.node/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for cheaha.node diff --git a/openstack/nodeimage.pkr.hcl b/openstack/nodeimage.pkr.hcl index a2edb03..5e4a245 100644 --- a/openstack/nodeimage.pkr.hcl +++ b/openstack/nodeimage.pkr.hcl @@ -19,6 +19,7 @@ build { provisioner "ansible" { playbook_file = "./ansible/node.yml" + roles_path = "./ansible/roles" extra_arguments = [ "--extra-vars", "root_ssh_key='${var.root_ssh_key}'" ] -- GitLab