]> git.phdru.name Git - ansible.git/blobdiff - playbooks/debian/roles/phd/tasks/main.yml
Feat: Use module `stat` instead of command `test`
[ansible.git] / playbooks / debian / roles / phd / tasks / main.yml
index 7ab7ba1d50574c21de7734da3b7dd3e2a5053812..4c00ec5d2d369e06b92bd489fa10d1df1ce921a7 100644 (file)
@@ -1,12 +1,12 @@
 - name: Test if user phd already exists
-  command: test -f ~/.profile -a -f ~/.shellrc
-  failed_when: false
-  register: phd_exist
-  changed_when: phd_exist.rc != 0
+  stat:
+    path: "{{ item }}"
+  register: phd_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:
@@ -16,4 +16,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