summaryrefslogtreecommitdiff
path: root/home/.ansible/roles/new_host/tasks/backup_system_files.yml
diff options
context:
space:
mode:
authorboom2 <blizzack@blizzack.com>2023-12-14 17:24:25 -0500
committerboom2 <blizzack@blizzack.com>2023-12-14 17:24:25 -0500
commitf30709d7dbe88d82c4df66c476db36cb5c0ce903 (patch)
treeca861d7aa3e30c73a4fefeb9186f221cf15a8ff5 /home/.ansible/roles/new_host/tasks/backup_system_files.yml
parentd8a7729358a2fd3b911022e45d0197fda3e5da94 (diff)
- 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"
Diffstat (limited to 'home/.ansible/roles/new_host/tasks/backup_system_files.yml')
-rw-r--r--home/.ansible/roles/new_host/tasks/backup_system_files.yml60
1 files changed, 60 insertions, 0 deletions
diff --git a/home/.ansible/roles/new_host/tasks/backup_system_files.yml b/home/.ansible/roles/new_host/tasks/backup_system_files.yml
new file mode 100644
index 0000000..d04a45a
--- /dev/null
+++ b/home/.ansible/roles/new_host/tasks/backup_system_files.yml
@@ -0,0 +1,60 @@
+# - a bit of a contrived example of backing up files on a managed host
+#
+# https://stackoverflow.com/questions/24162996/how-to-move-rename-a-file-using-an-ansible-task-on-a-remote-system
+
+---
+- 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.dist
+ - hosts
+ - fstab
+ - inittab
+ become: true
+ become_user: root
+ tags: ['backup_system_files']
+
+- name: backup slackpkg files
+ ansible.builtin.copy:
+ src: /etc/slackpkg/{{ item }}
+ remote_src: true
+ dest: "{{ backup_etc_dir }}/"
+ mode: preserve
+ with_items:
+ - blacklist~
+ - mirrors~
+ become: true
+ become_user: root
+ tags: ['backup_slackpkg_files']
+
+- name: rename our test files
+ ansible.builtin.shell: |
+ sudo mv {{ backup_etc_dir }}/hosts.allow~ {{ backup_etc_dir }}/hosts.allow
+ sudo mv {{ backup_etc_dir }}/hosts.deny~ {{ backup_etc_dir }}/hosts.deny
+ sudo mv {{ backup_etc_dir }}/sudoers.dist {{ backup_etc_dir }}/sudoers
+ sudo mv {{ backup_etc_dir }}/blacklist~ {{ backup_etc_dir }}/blacklist
+ sudo mv {{ backup_etc_dir }}/mirrors~ {{ backup_etc_dir }}/mirrors
+ exit 0
+ tags: ['rename_files']