From f30709d7dbe88d82c4df66c476db36cb5c0ce903 Mon Sep 17 00:00:00 2001 From: boom2 Date: Thu, 14 Dec 2023 17:24:25 -0500 Subject: - add "new_host" role for system setup - no longer use "all" to mention all hosts in playbooks - update of hosts file to now use localhost as "test" --- .../10-playbook-copy-system-files-on-node.yml | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 ansible-practice/system/10-playbook-copy-system-files-on-node.yml (limited to 'ansible-practice/system/10-playbook-copy-system-files-on-node.yml') diff --git a/ansible-practice/system/10-playbook-copy-system-files-on-node.yml b/ansible-practice/system/10-playbook-copy-system-files-on-node.yml new file mode 100644 index 0000000..c073d44 --- /dev/null +++ b/ansible-practice/system/10-playbook-copy-system-files-on-node.yml @@ -0,0 +1,59 @@ +# create backup copies of system files on control node +# +# https://www.freekb.net/Article?id=759 +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html +# https://phoenixnap.com/kb/ansible-check-if-file-exists +# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_variables.html#registering-variables +# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_conditionals.html +# +# https://www.howtouselinux.com/post/ansible-copy-module-examples-to-copy-file-to-remote-server +# https://docs.ansible.com/ansible/latest/plugins/become.html +# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_privilege_escalation.html +# +# had to run the command like so: +# +# ansible-playbook 10-playbook-copy-system-files-on-node.yml --ask-become-pass +# +# -or- +# +# ansible-playbook 10-playbook-copy-system-files-on-node.yml -K +# +--- +- name: "10 - custom ansible - backup system files on node" + hosts: dev + tasks: + - name: check backup directory status + ansible.builtin.stat: + path: "{{ backup_etc_dir }}" + register: backup_dir + tags: ['backup_dir_status'] + + - name: create backup directory if it does not exist + ansible.builtin.file: + path: "{{ backup_etc_dir }}" + state: directory + become: true + become_user: root + when: backup_dir.stat.isdir is not defined + tags: ['create_backup_dir'] + + - name: backup of system files + ansible.builtin.copy: + src: /etc/{{ item }} + remote_src: true + dest: "{{ backup_etc_dir }}/" + mode: preserve + with_items: + - hosts.allow + - hosts.deny + - inetd.conf + - sudoers + - hosts + - fstab + - inittab + become: true + become_user: root + when: backup_dir.stat.isdir is defined + tags: ['backup_files'] -- cgit v1.2.3-54-g00ecf