]> git.phdru.name Git - ansible.git/blobdiff - playbooks/debian/roles/root/tasks/mc.yml
Feat: Add `changed_when`
[ansible.git] / playbooks / debian / roles / root / tasks / mc.yml
index e46d622f7731aeab7a24fb220f2e5f2762f8846e..332015ef7d3facd2480290e9d892eaca816480ac 100644 (file)
@@ -1,12 +1,14 @@
 - name: "Setup root mc - check mc links"
   become: true
-  command: test -L ~root/.cache/mc -a -L ~root/.config/mc -a -L ~root/.local/share/mc
-  failed_when: false
+  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.rc == 0
+  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length == 3
 
 - name: "Setup root mc - create directories for mc links"
   become: true
@@ -15,7 +17,7 @@
     state: directory
     mode: "0700"
   loop: ['.cache', '.config', '.local/share']
-  when: links_exist.rc != 0
+  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
 
 - name: "Setup root mc - remove mc directories"
   become: true
@@ -23,7 +25,7 @@
     path: "~root/{{ item }}"
     state: absent
   loop: ['.cache/mc', '.config/mc', '.local/share/mc']
-  when: links_exist.rc != 0
+  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
 
 - name: "Setup root mc - link mc directories (1)"
   become: true
@@ -33,7 +35,7 @@
     src: "../.mc"
     force: yes
   loop: ['.cache/mc', '.config/mc']
-  when: links_exist.rc != 0
+  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
 
 - name: "Setup root mc - link mc directories (2)"
   become: true
@@ -43,9 +45,9 @@
     src: "../../.mc"
     force: yes
   loop: ['.local/share/mc']
-  when: links_exist.rc != 0
+  when: links_exist.results|selectattr('stat.exists')|selectattr('stat.islnk')|list|length != 3
 
-- name: "Setup root ms - overwrite files from ~phd/admin"
+- name: "Setup root mc - overwrite files from ~phd/admin"
   become: true
   copy:
     src: "~phd/admin/home/root/.mc/{{ item }}"
@@ -56,4 +58,3 @@
     mode: "0600"
     force: yes
   loop: ['hotlist', 'ini', 'panels.ini']
-