From dc5d2d6a37271399349568ae1a27c8e67da8ce48 Mon Sep 17 00:00:00 2001 From: Rumiah Kessel Date: Tue, 13 Jun 2023 11:18:16 -0700 Subject: [PATCH] added goslmailer install, uninstall, and role --- playbooks/README.md | 15 +- playbooks/goslmailer_install.yml | 137 ++++++++++++++++++ playbooks/goslmailer_uninstall.yml | 54 +++++++ playbooks/roles/goslmailer/defaults/main.yml | 2 + playbooks/roles/goslmailer/tasks/main.yml | 16 ++ playbooks/roles/goslmailer/vars/main.yml | 1 + playbooks/roles/slurm/templates/slurm.conf.j2 | 1 + 7 files changed, 225 insertions(+), 1 deletion(-) create mode 100644 playbooks/goslmailer_install.yml create mode 100644 playbooks/goslmailer_uninstall.yml create mode 100644 playbooks/roles/goslmailer/defaults/main.yml create mode 100644 playbooks/roles/goslmailer/tasks/main.yml create mode 100644 playbooks/roles/goslmailer/vars/main.yml diff --git a/playbooks/README.md b/playbooks/README.md index 4ed523b0..accb78bd 100644 --- a/playbooks/README.md +++ b/playbooks/README.md @@ -1,3 +1,16 @@ +## Nix + To install the Nix package manager run the install_nix.yml playbook. + To remove the Nix package manager run the uninstall_nix.yml playbook. -Both playbooks are idempotent. If you get an error running the uninstall_nix.yml playbook rerun the playbook. \ No newline at end of file + +Both playbooks are idempotent. If you get an error running the uninstall_nix.yml playbook rerun the playbook. + +## Goslmailer +To install goslmailer run the goslmailer_install.yml and enter the slack_bot_token from the [slack bot app](https://app.slack.com/app-settings/T04PVJTPVCJ/A05AGQ7HNBX) (OAuth & Permissions -> OAuth Tokens for Your Workspace -> Bot User OAuth Token). Followed by the app password for the notification email (do-not-reply@safe.ai). This is generated by the following steps: +1. Enable 2fa for the account [https://myaccount.google.com/security](https://myaccount.google.com/security). Make sure you select the do-not-reply account on the login screen or change to it in the top right corner. +1. Now go to: [https://myaccount.google.com/apppasswords](https://myaccount.google.com/apppasswords). Again ensure you are on the correct account. +1. Press the "select app" dropdown and select "other". Then enter any name you like such as "CAIS Notifications". This will only be used here but should be recognizable. +1. Press "Generate" in the bottom right and copy this password (Copy this into terminal window when prompted). + +To uninstall goslmailer run goslmailer_uninstall.yml. Note that this does not remove the MailProg entry from the slurm.conf. This won't cause problems but will be silently erroring in the slurmctld.log. So if you want to be clean you can remove that from the config. \ No newline at end of file diff --git a/playbooks/goslmailer_install.yml b/playbooks/goslmailer_install.yml new file mode 100644 index 00000000..cdc30a15 --- /dev/null +++ b/playbooks/goslmailer_install.yml @@ -0,0 +1,137 @@ +- name: Download and unpack from github as well as get user prompt + hosts: bastion + become: true + vars_prompt: + - name: slack_bot_token + prompt: "Enter the slack bot token" + - name: app_password + prompt: "Enter the app password for the email account" + tasks: + - name: Include a role dynamically + include_role: + name: goslmailer + + - name: Copy binaries + copy: + src: /tmp/goslmailer/goslmailer + dest: /bin + owner: slurm + group: slurm + mode: '0770' + + - copy: + src: /tmp/goslmailer/gobler + dest: /bin + owner: slurm + group: slurm + mode: '0770' + + - name: Create slack directory + file: + path: /var/spool/slack + state: directory + owner: slurm + group: slurm + mode: '0770' + + - name: Copy Notification templates + copy: + src: "/tmp/goslmailer/notification_templates" + dest: /etc/slurm/ + mode: '0744' + owner: slurm + group: slurm + + - name: Copy goslmailer.conf + copy: + src: "/tmp/goslmailer/goslmailer.conf" + dest: /etc/slurm/goslmailer.conf + mode: '0600' + owner: slurm + group: slurm + + - name: Copy gobler.conf + copy: + src: "/tmp/goslmailer/gobler.conf" + dest: /etc/slurm/gobler.conf + mode: '0600' + owner: slurm + group: slurm + + - name: Copy gobler.service + copy: + src: "/tmp/goslmailer/gobler.service" + dest: /etc/systemd/system/ + mode: '0644' + owner: root + group: root + + - name: Reload systemd daemon + systemd: + daemon_reload: yes + + - name: Disable gobler service + systemd: + name: gobler + enabled: false + + - name: Install mutt + vars: + package_name: + - mutt + include_role: + name: safe_yum + + - name: Copy Muttrc.local + copy: + src: "/tmp/goslmailer/Muttrc.local" + dest: /etc/Muttrc.local + mode: '0600' + + - name: Restart postfix service + systemd: + name: postfix + state: restarted + enabled: yes + + - name: Create goslmailer.log + file: + path: /data/spool/goslmailer.log + state: touch + mode: '0600' + owner: slurm + group: slurm + + - name: Set ownership and permissions for spool + file: + path: "{{ item.path }}" + state: directory + mode: "{{ item.mode }}" + owner: root + group: root + loop: + - { path: '/var/spool/postfix', mode: '0755'} + - { path: '/var/spool/mail', mode: '0755'} + + - name: Set ownership and permissions for Muttrc + file: + path: "{{ item.path }}" + state: file + mode: "{{ item.mode }}" + owner: slurm + group: slurm + loop: + - { path: '/etc/Muttrc', mode: '0600'} + - { path: '/etc/Muttrc.local', mode: '0600'} + + - name: Edit config files + replace: + path: "{{ item.path }}" + regexp: "{{ item.regex }}" + replace: "{{ item.new }}" + loop: + - { path: '/etc/slurm/goslmailer.conf', regex: "\\$SLACK_BOT_TOKEN", new: "{{ slack_bot_token }}"} + - { path: '/etc/slurm/gobler.conf', regex: "\\$SLACK_BOT_TOKEN", new: "{{ slack_bot_token }}"} + - { path: '/etc/Muttrc.local', regex: "\\$EMAIL_ADDRESS", new: "do-not-reply@safe.ai"} + - { path: '/etc/Muttrc.local', regex: "\\$PLAIN_TEXT_NAME", new: "CAIS Notifications"} + - { path: '/etc/Muttrc.local', regex: "\\$APP_PASSWORD", new: "{{ app_password }}"} \ No newline at end of file diff --git a/playbooks/goslmailer_uninstall.yml b/playbooks/goslmailer_uninstall.yml new file mode 100644 index 00000000..73964e8d --- /dev/null +++ b/playbooks/goslmailer_uninstall.yml @@ -0,0 +1,54 @@ +- name: Uninstall goslmailer + hosts: bastion + become: true + tasks: + - name: Remove goslmailer binary + file: + path: /bin/goslmailer + state: absent + + - name: Remove gobler binary + file: + path: /bin/gobler + state: absent + + - name: Remove slack directory + file: + path: /var/spool/slack + state: absent + + - name: Remove notification_templates directory + file: + path: /etc/slurm/notification_templates + state: absent + + - name: Remove goslmailer.log file + file: + path: /var/log/goslmailer.log + state: absent + + - name: Remove goslmailer.conf file + file: + path: /etc/slurm/goslmailer.conf + state: absent + + - name: Remove gobler.conf file + file: + path: /etc/slurm/gobler.conf + state: absent + + - name: Stop gobler service + systemd: + name: gobler + state: stopped + enabled: false + ignore_errors: True + + - name: Remove gobler.service file + file: + path: /etc/systemd/system/gobler.service + state: absent + + - name: Reload systemd daemon + systemd: + daemon_reload: true \ No newline at end of file diff --git a/playbooks/roles/goslmailer/defaults/main.yml b/playbooks/roles/goslmailer/defaults/main.yml new file mode 100644 index 00000000..c115f005 --- /dev/null +++ b/playbooks/roles/goslmailer/defaults/main.yml @@ -0,0 +1,2 @@ +goslmailer_version: v2.7.1.1 +download_checksum: sha512:9e48c639889c76278d4dd4874a5110c924fe2ea1784d1a11e74ef6a99371f6a8843fff376cc81a8b1fcf5fac335b19b5801fa9d373153f3378e4752c86cd3b2f \ No newline at end of file diff --git a/playbooks/roles/goslmailer/tasks/main.yml b/playbooks/roles/goslmailer/tasks/main.yml new file mode 100644 index 00000000..009d5d0c --- /dev/null +++ b/playbooks/roles/goslmailer/tasks/main.yml @@ -0,0 +1,16 @@ +- name: Download and unpack files + block: + - name: Download zip + get_url: + url: "{{ download_path }}" + dest: /tmp + checksum: "{{ download_checksum }}" + - name: Create temp directory + file: + path: /tmp/goslmailer + state: directory + - name: Extract installer files + unarchive: + src: /tmp/goslmailer-{{ goslmailer_version }}.zip + remote_src: false + dest: /tmp/goslmailer/ \ No newline at end of file diff --git a/playbooks/roles/goslmailer/vars/main.yml b/playbooks/roles/goslmailer/vars/main.yml new file mode 100644 index 00000000..c61f5112 --- /dev/null +++ b/playbooks/roles/goslmailer/vars/main.yml @@ -0,0 +1 @@ +download_path: "https://github.com/centerforaisafety/goslmailer/releases/download/{{ goslmailer_version }}/goslmailer-{{ goslmailer_version }}.zip" \ No newline at end of file diff --git a/playbooks/roles/slurm/templates/slurm.conf.j2 b/playbooks/roles/slurm/templates/slurm.conf.j2 index 33ac5131..3deb5bdc 100755 --- a/playbooks/roles/slurm/templates/slurm.conf.j2 +++ b/playbooks/roles/slurm/templates/slurm.conf.j2 @@ -47,6 +47,7 @@ CommunicationParameters=NoAddrCache TopologyPlugin=topology/tree TreeWidth=2048 SlurmctldParameters=enable_configless +MailProg=/bin/goslmailer {% if sacct_limits|bool %} AccountingStorageTRES=gres/gpu