- name: Test if user phd already exists 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_exists.results|selectattr('stat.exists')|list|length == 2 - name: Create and setup user phd block: - name: Create system groups become: true group: name: "{{ item }}" system: true loop: "{{ system_groups.split(',') }}" - name: Create group phd become: true group: name: phd - name: Add user phd become: true user: name: phd group: phd groups: "{{ system_groups }}" - name: Remove default mc directories file: path: "{{ item }}" state: absent loop: ['~/.cache/mc', '~/.config/mc', '~/.local/share/mc'] - name: Upload and extract home archive unarchive: src: ~/archive/STORE/phd/Home/phd.tar.bz2 dest: /home register: phd_extracted failed_when: "(ansible_facts.os_family == 'Debian' and 'rc' in phd_extracted and phd_extracted.rc != 0) or (ansible_facts.os_family == 'RedHat' and ('rc' in phd_extracted and phd_extracted.rc not in [0, 139]))" - name: Add alias (Debian) become: true lineinfile: path: /etc/aliases regexp: "^root: phd$" line: "root: phd" when: ansible_facts.os_family == 'Debian' when: phd_exists.results|selectattr('stat.exists')|list|length != 2 - name: Add alias (RedHat) become: true lineinfile: path: /etc/aliases regexp: "^root: phd$" line: "root: phd" when: ansible_facts.os_family == 'RedHat'