diff options
| author | boom2 <blizzack@blizzack.com> | 2023-12-21 15:49:16 -0500 |
|---|---|---|
| committer | boom2 <blizzack@blizzack.com> | 2023-12-21 15:49:16 -0500 |
| commit | 200680e7c8cbd6b4426c3ce232568b1e06446bde (patch) | |
| tree | b122f103cc4dce8cea078c20dac107612399640e /ansible-practice/system/17-playbook-slackbuild-rsync-repo.yml | |
| parent | a21b2f4bb64bd0f633d8a6a15f27a73103df70c0 (diff) | |
- renamed playbook to follow convention
-- add /etc/rc.d/rc.M in 'fetch file playbook' for future clamav playbook
Diffstat (limited to 'ansible-practice/system/17-playbook-slackbuild-rsync-repo.yml')
| -rw-r--r-- | ansible-practice/system/17-playbook-slackbuild-rsync-repo.yml | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/ansible-practice/system/17-playbook-slackbuild-rsync-repo.yml b/ansible-practice/system/17-playbook-slackbuild-rsync-repo.yml new file mode 100644 index 0000000..597d8c0 --- /dev/null +++ b/ansible-practice/system/17-playbook-slackbuild-rsync-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 +# |
