]> git.phdru.name Git - ansible.git/commitdiff
Feat(playbooks/fetch-push): Fetch/push a file
authorOleg Broytman <phd@phdru.name>
Wed, 23 Mar 2022 02:02:54 +0000 (05:02 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 23 Mar 2022 02:02:54 +0000 (05:02 +0300)
Backup a remote file. Update it back.

playbooks/fetch-push/fetch [new file with mode: 0755]
playbooks/fetch-push/fetch.yml [new file with mode: 0644]
playbooks/fetch-push/push [new file with mode: 0755]
playbooks/fetch-push/push.yml [new file with mode: 0644]

diff --git a/playbooks/fetch-push/fetch b/playbooks/fetch-push/fetch
new file mode 100755 (executable)
index 0000000..1a15823
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+start_dir="`pwd`" &&
+fetch_push_dir="`dirname \"$0\"`" &&
+exec "$HOME"/.virtualenvs/ansible/bin/ansible-playbook -v "$fetch_push_dir"/fetch.yml -e start_dir="$start_dir" "$@"
diff --git a/playbooks/fetch-push/fetch.yml b/playbooks/fetch-push/fetch.yml
new file mode 100644 (file)
index 0000000..37510a4
--- /dev/null
@@ -0,0 +1,9 @@
+- name: "Fetch {{ file }}"
+  hosts: "{{ hosts | default('all') }}"
+  gather_facts: false
+  tasks:
+    - name: Fetch files
+      fetch:
+        src: "{{ file }}"
+        dest: "{{ start_dir }}/{{ inventory_hostname }}/"
+        flat: yes
diff --git a/playbooks/fetch-push/push b/playbooks/fetch-push/push
new file mode 100755 (executable)
index 0000000..624c755
--- /dev/null
@@ -0,0 +1,5 @@
+#! /bin/sh
+
+start_dir="`pwd`" &&
+fetch_push_dir="`dirname \"$0\"`" &&
+exec "$HOME"/.virtualenvs/ansible/bin/ansible-playbook -v "$fetch_push_dir"/push.yml -e start_dir="$start_dir" "$@"
diff --git a/playbooks/fetch-push/push.yml b/playbooks/fetch-push/push.yml
new file mode 100644 (file)
index 0000000..247ac74
--- /dev/null
@@ -0,0 +1,12 @@
+- name: "Push {{ file }}"
+  hosts: "{{ hosts | default('all') }}"
+  become: yes
+  gather_facts: false
+  tasks:
+    - name: Copy files
+      copy:
+        src: "{{ start_dir }}/{{ inventory_hostname }}/{{ file }}"
+        dest: "{{ dest_dir }}"
+        owner: "{{ owner | default('root') }}"
+        group: "{{ group | default('root') }}"
+        mode: "{{ mode | default('0644') }}"