]> git.phdru.name Git - ansible.git/blobdiff - playbooks/debian/roles/root/tasks/mc.yml
Refactor: Join tasks into blocks to factor out conditions
[ansible.git] / playbooks / debian / roles / root / tasks / mc.yml
index ec8052308c4f808397fb43f591ce2b20c19ca81f..c27e80e99d076681ad6c51e1e000b178063a7a3b 100644 (file)
@@ -3,47 +3,46 @@
   stat:
     path: "{{ item }}"
   register: links_exist
+  changed_when: not links_exist.stat.exists
   loop: ['~root/.cache/mc', '~root/.config/mc', '~root/.local/share/mc']
 
 - debug:
     msg: "mc links have already been created"
   when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length == 3
 
-- name: "Setup root mc - create directories for mc links"
-  become: true
-  file:
-    path: "~root/{{ item }}"
-    state: directory
-    mode: "0700"
-  loop: ['.cache', '.config', '.local/share']
-  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
+- block:
+    - name: "Setup root mc - create directories for mc links"
+      become: true
+      file:
+        path: "~root/{{ item }}"
+        state: directory
+        mode: "0700"
+      loop: ['.cache', '.config', '.local/share']
 
-- name: "Setup root mc - remove mc directories"
-  become: true
-  file:
-    path: "~root/{{ item }}"
-    state: absent
-  loop: ['.cache/mc', '.config/mc', '.local/share/mc']
-  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
+    - name: "Setup root mc - remove mc directories"
+      become: true
+      file:
+        path: "~root/{{ item }}"
+        state: absent
+      loop: ['.cache/mc', '.config/mc', '.local/share/mc']
 
-- name: "Setup root mc - link mc directories (1)"
-  become: true
-  file:
-    path: "~root/{{ item }}"
-    state: link
-    src: "../.mc"
-    force: yes
-  loop: ['.cache/mc', '.config/mc']
-  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
+    - name: "Setup root mc - link mc directories (1)"
+      become: true
+      file:
+        path: "~root/{{ item }}"
+        state: link
+        src: "../.mc"
+        force: yes
+      loop: ['.cache/mc', '.config/mc']
 
-- name: "Setup root mc - link mc directories (2)"
-  become: true
-  file:
-    path: "~root/{{ item }}"
-    state: link
-    src: "../../.mc"
-    force: yes
-  loop: ['.local/share/mc']
+    - name: "Setup root mc - link mc directories (2)"
+      become: true
+      file:
+        path: "~root/{{ item }}"
+        state: link
+        src: "../../.mc"
+        force: yes
+      loop: ['.local/share/mc']
   when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
 
 - name: "Setup root mc - overwrite files from ~phd/admin"