From df8bae6df7a02df7a7c55aae16b1a434f0b31c0a Mon Sep 17 00:00:00 2001 From: Solal Nathan Date: Wed, 10 Feb 2021 11:01:42 +0100 Subject: [PATCH 1/3] Add utils --- utils/README.md | 4 +++ logrotate.yml => utils/logrotate.yml | 0 .../nuke_radius_dbs.yml | 0 utils/re2o_mail_server.yml | 13 ++++++++ utils/reboot_needed_check.yml | 31 +++++++++++++++++++ upgrade.yml => utils/upgrade.yml | 0 utils/version_check.yml | 19 ++++++++++++ 7 files changed, 67 insertions(+) create mode 100644 utils/README.md rename logrotate.yml => utils/logrotate.yml (100%) rename nuke_radius_dbs.yml => utils/nuke_radius_dbs.yml (100%) create mode 100755 utils/re2o_mail_server.yml create mode 100755 utils/reboot_needed_check.yml rename upgrade.yml => utils/upgrade.yml (100%) create mode 100755 utils/version_check.yml diff --git a/utils/README.md b/utils/README.md new file mode 100644 index 0000000..651404b --- /dev/null +++ b/utils/README.md @@ -0,0 +1,4 @@ +# Utils + +A repository of Ansible Playbooks that are useful, as little script or various +utilities, but not used in production. diff --git a/logrotate.yml b/utils/logrotate.yml similarity index 100% rename from logrotate.yml rename to utils/logrotate.yml diff --git a/nuke_radius_dbs.yml b/utils/nuke_radius_dbs.yml similarity index 100% rename from nuke_radius_dbs.yml rename to utils/nuke_radius_dbs.yml diff --git a/utils/re2o_mail_server.yml b/utils/re2o_mail_server.yml new file mode 100755 index 0000000..79fd7ff --- /dev/null +++ b/utils/re2o_mail_server.yml @@ -0,0 +1,13 @@ +--- +# Deploy Re2o mail service +- hosts: mail.auro.re + vars: + service_repo: https://gitea.auro.re/aurore/re2o-mail-server.git + service_name: mail-server + service_version: aurore + service_config: + hostname: re2o-test.adm.auro.re # use test instance for now, should be changed for prod! + username: service-user + password: "{{ vault_serviceuser_passwd }}" + roles: + - re2o-service diff --git a/utils/reboot_needed_check.yml b/utils/reboot_needed_check.yml new file mode 100755 index 0000000..5759c53 --- /dev/null +++ b/utils/reboot_needed_check.yml @@ -0,0 +1,31 @@ +#!/usr/bin/env ansible-playbook +--- +# Check if a reboot is required by the installation of some packages (ie kernel) +- hosts: localhost + tasks: + - name: Make sure local file exist but is empty # weird hack, I know + copy: + dest: /tmp/ansible_dump_reboot_needed.txt + content: "" + force: true + +- hosts: all,!unifi,!escalope.adm.auro.re,!loki.adm.auro.re,!viviane.adm.auro.re,!vpn-ovh.adm.auro.re + tasks: + # Register the output of the file /var/run/reboot-required.pkgs + - name: Register if boot is required + shell: if [ -e /var/run/reboot-required.pkgs ]; then cat /var/run/reboot-required.pkgs; fi + register: result + + - name: DEBUG + debug: + msg: "{{ ansible_facts['nodename'] }} : {{ result.stdout }}" + when: result.stdout != "" + + # Add info line by line + - name: Dump all info into the local file + delegate_to: localhost + lineinfile: + path: /tmp/ansible_dump_reboot_needed.txt + line: "{{ ansible_facts['nodename'] }} : {{ result.stdout }}" + when: result.stdout != "" + diff --git a/upgrade.yml b/utils/upgrade.yml similarity index 100% rename from upgrade.yml rename to utils/upgrade.yml diff --git a/utils/version_check.yml b/utils/version_check.yml new file mode 100755 index 0000000..e608e43 --- /dev/null +++ b/utils/version_check.yml @@ -0,0 +1,19 @@ +#!/usr/bin/env ansible-playbook +--- +# Check for the distribution +- hosts: localhost + tasks: + - name: Delete local tmp file + file: + path: /tmp/ansible_dump_dist_version.txt + state: absent + +- hosts: all,!unifi + tasks: + # Add info line by line + - name: Dump all info into the local file + delegate_to: localhost + lineinfile: + path: /tmp/ansible_dump_dist_version.txt + line: "[{{ ansible_facts['nodename'] }}] {{ansible_fqdn}} : {{ + ansible_distribution }} {{ ansible_distribution_version }}" From 08891be5a30c67c1332a97496655bc15f0d6ebff Mon Sep 17 00:00:00 2001 From: Solal Nathan Date: Wed, 10 Feb 2021 11:04:06 +0100 Subject: [PATCH 2/3] fix if file is not already present --- utils/version_check.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/utils/version_check.yml b/utils/version_check.yml index e608e43..b543053 100755 --- a/utils/version_check.yml +++ b/utils/version_check.yml @@ -3,10 +3,11 @@ # Check for the distribution - hosts: localhost tasks: - - name: Delete local tmp file - file: - path: /tmp/ansible_dump_dist_version.txt - state: absent + - name: Make sure local file exist but is empty # weird hack, I know + copy: + dest: /tmp/ansible_dump_reboot_needed.txt + content: "" + force: true - hosts: all,!unifi tasks: From 63f0ebec7dbe91913a8741a746767dc51fc2ebac Mon Sep 17 00:00:00 2001 From: Solal Nathan Date: Wed, 10 Feb 2021 11:07:36 +0100 Subject: [PATCH 3/3] Fix yaml lint --- utils/reboot_needed_check.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/reboot_needed_check.yml b/utils/reboot_needed_check.yml index 5759c53..4f48a3d 100755 --- a/utils/reboot_needed_check.yml +++ b/utils/reboot_needed_check.yml @@ -28,4 +28,3 @@ path: /tmp/ansible_dump_reboot_needed.txt line: "{{ ansible_facts['nodename'] }} : {{ result.stdout }}" when: result.stdout != "" -