summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ansible-practice/system/13_1-create-update-user-with-prompt.yml2
-rw-r--r--ansible-practice/system/15-fetch-file.yml45
-rw-r--r--ansible-practice/system/16-test-slackware-version.yml52
-rw-r--r--ansible-practice/system/17-rsync-slackbuilds-repo.yml92
-rw-r--r--ansible_stuff.org17
5 files changed, 197 insertions, 11 deletions
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
+#
diff --git a/ansible_stuff.org b/ansible_stuff.org
index 3b7cf61..ea0f832 100644
--- a/ansible_stuff.org
+++ b/ansible_stuff.org
@@ -1043,6 +1043,23 @@ will bite me in the ass someday.
- i've seen references online that say this does not work well.
will need to test this
+* <2023-12-20 Wed> ---------------------------------------------------------
+
+- learned a bit about ansible.builtin.fetch
+ - copied files from a managed host(s) to the controller
+- started working on playbooks to invoke an sbopkg rsync on a host
+ - had to perform a bunch of bash trix to get what i want
+ - cut command
+ https://stackoverflow.com/questions/19482123/extract-part-of-a-string-using-bash-cut-split
+ https://stackoverflow.com/questions/6594085/remove-first-character-of-a-string-in-bash
+ https://www.geeksforgeeks.org/remove-last-character-from-string-in-linux/
+ - tr command
+ https://unix.stackexchange.com/questions/9647/how-can-i-find-and-replace-with-a-new-line
+ https://stackoverflow.com/questions/19345872/how-to-remove-a-newline-from-a-string-in-bash
+ https://www.delftstack.com/howto/linux/use-tr-command-in-linux-bash/
+ - sed command
+ https://unix.stackexchange.com/questions/144298/delete-the-last-character-of-a-string-using-string-manipulation-in-shell-script
+
* references
2023-12-16 -- the following is a lists of ansible related URLs compiled so far.