]> git.phdru.name Git - ansible.git/blobdiff - playbooks/debian/roles/phd/tasks/main.yml
Refactor: Join tasks into blocks to factor out conditions
[ansible.git] / playbooks / debian / roles / phd / tasks / main.yml
index 455605f45225f57ee9cd14ba4ef9505991f20cce..dfd87800724c161c963b389bd628d338e38f9663 100644 (file)
@@ -1,11 +1,13 @@
 - name: Test if user phd already exists
-  command: test -f ~/.profile -a -f ~/.shellrc
-  ignore_errors: true
-  register: phd_exist
+  stat:
+    path: "{{ item }}"
+  register: phd_exists
+  changed_when: not phd_exists.stat.exists
+  loop: ['~/.profile', '~/.shellrc']
 
 - debug:
     msg: "User phd has already been created"
-  when: phd_exist.rc == 0
+  when: phd_exists.results|selectattr('stat.exists')|list|length == 2
 
 - name: Create and setup user phd
   block:
@@ -15,4 +17,4 @@
       unarchive:
         src: ~/archive/STORE/phd/Home/phd.tar.bz2
         dest: /home
-  when: phd_exist.rc != 0
+  when: phd_exists.results|selectattr('stat.exists')|list|length != 2