From a21b2f4bb64bd0f633d8a6a15f27a73103df70c0 Mon Sep 17 00:00:00 2001 From: boom2 Date: Thu, 21 Dec 2023 15:15:38 -0500 Subject: - add slackware playbooks -- conditional checks on slackware release verison -- rsync sbopkg --- .../system/13_1-create-update-user-with-prompt.yml | 2 +- ansible-practice/system/15-fetch-file.yml | 45 ++++++++--- .../system/16-test-slackware-version.yml | 52 ++++++++++++ .../system/17-rsync-slackbuilds-repo.yml | 92 ++++++++++++++++++++++ 4 files changed, 180 insertions(+), 11 deletions(-) create mode 100644 ansible-practice/system/16-test-slackware-version.yml create mode 100644 ansible-practice/system/17-rsync-slackbuilds-repo.yml (limited to 'ansible-practice') diff --git a/ansible-practice/system/13_1-create-update-user-with-prompt.yml b/ansible-practice/system/13_1-create-update-user-with-prompt.yml index 7bd0760..5b16906 100644 --- a/ansible-practice/system/13_1-create-update-user-with-prompt.yml +++ b/ansible-practice/system/13_1-create-update-user-with-prompt.yml @@ -43,7 +43,7 @@ - name: remove users ssh keys ansible.builtin.file: - path: "{{ item.path }}" + path: "{{ item.path }}" state: absent with_items: "{{ ssh_keys.files }}" tags: ['remove_ssh_files'] diff --git a/ansible-practice/system/15-fetch-file.yml b/ansible-practice/system/15-fetch-file.yml index ed8690d..0236efe 100644 --- a/ansible-practice/system/15-fetch-file.yml +++ b/ansible-practice/system/15-fetch-file.yml @@ -1,23 +1,48 @@ +# fetch/download a file(s) from managed nodes to the controller node # -# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/fetch_module.html +# - use cases: +# - pulling log files +# - grabbing public keys # -# - need to play with looping thru items # --- - name: "15 - custom ansible - fetch file" hosts: dev become: yes # Run tasks with root/sudo privileges + vars: + sys_file_list: + - /etc/rc.d/rc.firewall + - /etc/ssh/sshd_config +# +# - playing w/ loops as well +# tasks: - - name: pull sshd config + - name: pull sshd & firewall configs ansible.builtin.fetch: - src: /etc/ssh/sshd_config + src: "{{ item }}" dest: ~/repos/ansible_repo/ansible-practice/system/ - tags: ['fetch_sshd_config'] + loop: "{{ sys_file_list }}" + tags: ['fetch_sys_configs'] - - name: pull sshd config - ansible.builtin.fetch: - src: /etc/rc.d/rc.firewall - dest: ~/repos/ansible_repo/ansible-practice/system/ - tags: ['fetch_firewall_config'] +# +# - essentially, the same code as above except done one task at a time +# +# - name: pull sshd config +# ansible.builtin.fetch: +# src: /etc/ssh/sshd_config +# dest: ~/repos/ansible_repo/ansible-practice/system/ +# tags: ['fetch_sshd_config'] +# +# - name: pull firewall config +# ansible.builtin.fetch: +# src: /etc/rc.d/rc.firewall +# dest: ~/repos/ansible_repo/ansible-practice/system/ +# tags: ['fetch_firewall_config'] +# +# References +# +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/fetch_module.html +# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_loops.html +# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#list-variables diff --git a/ansible-practice/system/16-test-slackware-version.yml b/ansible-practice/system/16-test-slackware-version.yml new file mode 100644 index 0000000..ed19c03 --- /dev/null +++ b/ansible-practice/system/16-test-slackware-version.yml @@ -0,0 +1,52 @@ +# test slackware version on host w/ conditonals +# +# - use cases: +# - set conditions depending on the version +# +--- +- name: "16 - custom ansible - test slackware version" + hosts: dev + + tasks: + - name: Print os info + ansible.builtin.debug: + msg: + - "distro = {{ ansible_distribution }}" + - "distro major version = {{ ansible_distribution_major_version }}" + - "distro release = {{ ansible_distribution_release }}" + - "distro version = {{ ansible_distribution_version }}" + + - name: is os version '-current' + ansible.builtin.debug: + msg: this slackware distro is '-current ! + when: + - ansible_facts['distribution'] == "Slackware" + - ansible_facts['distribution_release'] == "current" + tags: ['is_current'] + + - name: os version is not '-current' + ansible.builtin.debug: + msg: this slackware distro is NOT '-current ! + when: + - ansible_facts['distribution'] == "Slackware" + - ansible_facts['distribution_release'] != "current" + tags: ['is_not_current'] + + +# "ansible_distribution": "Slackware", +# "ansible_distribution_major_version": "15", +# "ansible_distribution_release": "current", +# "ansible_distribution_version": "15.0+", +# +# +# "ansible_distribution": "Slackware", +# "ansible_distribution_major_version": "15", +# "ansible_distribution_release": "stable", +# "ansible_distribution_version": "15.0", + + +# References +# +# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html +# +# diff --git a/ansible-practice/system/17-rsync-slackbuilds-repo.yml b/ansible-practice/system/17-rsync-slackbuilds-repo.yml new file mode 100644 index 0000000..597d8c0 --- /dev/null +++ b/ansible-practice/system/17-rsync-slackbuilds-repo.yml @@ -0,0 +1,92 @@ +# rsync slackbuilds repo +# +# - use cases: +# - get slackware hosts slackbuilds repo up-to-date +# +--- +- name: "17 - custom ansible - rsync slackbuilds repo" + become: yes # Run tasks with root/sudo privileges + hosts: dev + vars: + sbopkg_command: /usr/sbin/sbopkg + sbopkg_config: /etc/sbopkg/sbopkg.conf + + tasks: + - name: fail - if not a slackware host ! + ansible.builtin.fail: + msg: this host is not running Slackware + when: ansible_facts['distribution'] != "Slackware" + tags: ['test_slackware_host'] + + - name: "test - to see if '{{ sbopkg_command }}' exists" + ansible.builtin.stat: + path: "{{ sbopkg_command }}" + register: usr_sbin_sbopkg + tags: ['register_usr_sbin_sbopkg'] + + - name: "fail - if the '{{ sbopkg_command }}' command does not exist !" + ansible.builtin.fail: + msg: "this host does not have {{ sbopkg_command }} installed" + when: usr_sbin_sbopkg.stat.isreg is not defined + tags: ['test_sbopkg_exists'] + + - name: "test - to see if '{{ sbopkg_config }}' exists" + ansible.builtin.stat: + path: "{{ sbopkg_config }}" + register: etc_sbopkg_sbopkg_conf + tags: ['register_etc_sbopkg_sbopkg_conf'] + + - name: "fail - if '{{ sbopkg_config }}' does not exist !" + ansible.builtin.fail: + msg: "this host does not have {{ sbopkg_config }}" + when: etc_sbopkg_sbopkg_conf.stat.isreg is not defined + tags: ['test_sbopkg_conf_exists'] + + - name: "retrieve - the REPO_ROOT and REPO_NAME from {{ sbopkg_config }}" + ansible.builtin.shell: "grep -E '^REPO_ROOT|^REPO_NAME*' {{ sbopkg_config }} | cut -d ':' -f 2 | cut -c2- | rev | cut -c2- | rev | tr '\n' '/' | sed 's/.$//'" + register: sbopkg_conf_contents + when: usr_sbin_sbopkg.stat.isdir is defined + tags: ['get_repo_contents'] + + - name: remove - the sbopkg repo directory (when on a slackware-current host) + ansible.builtin.file: + path: "{{ sbopkg_conf_contents.stdout }}" + state: absent + when: ansible_facts['distribution_release'] == "current" + tags: ['delete_repo'] + + - name: "execute - rsync of our sbopkg repo inside of {{ sbopkg_conf_contents.stdout }} !" + ansible.builtin.shell: "{{ sbopkg_command }} -r" + tags: ['rsync_sbopkg'] + + +# - name: debugging info: reporting if sbopkg_conf_contents exists +# ansible.builtin.debug: +# msg: "{{ sbopkg_conf_contents.stdout }}" +# when: +# - sbopkg_conf_contents.stdout != "" +# tags: ['repo_recon2'] + +# - if our directory exists and it ends w/ -git remove it !! +# - name: remove if using -current repo +# ansible.builtin.debug: +# msg: "{{ sbopkg_conf_dir.stat }} is a directory" +# when: +# - sbopkg_conf_dir.stat.isdir is defined +# tags: ['repo_recon3'] + +# - if our directory exists and it ends w/ -git remove it !! +# - name: if on slackware-current: remove the sbopkg repo directory +# ansible.builtin.shell: rm -rf /var/lib/sbopkg/SBo-git +# when: +# - ansible_facts['distribution'] == "Slackware" +# - ansible_facts['distribution_release'] == "current" +# - sbopkg_conf_dir.stat.isdir is defined +# tags: ['delete_repo'] + +# References +# +# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/fail_module.html +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/stat_module.html +# -- cgit v1.2.3-54-g00ecf