- 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:
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