X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=playbooks%2Fdebian%2Froles%2Fphd%2Ftasks%2Fmain.yml;h=1ca3a4b3c8340b70fd436ce2a836328395618a41;hb=e2f84bb9d51c4452b61763857dee14db8bc32824;hp=98973042f96342b798268e71915f507ff76a0979;hpb=4ddac78094546713d0e96f88932a0a9cfd1432ae;p=ansible.git diff --git a/playbooks/debian/roles/phd/tasks/main.yml b/playbooks/debian/roles/phd/tasks/main.yml index 9897304..1ca3a4b 100644 --- a/playbooks/debian/roles/phd/tasks/main.yml +++ b/playbooks/debian/roles/phd/tasks/main.yml @@ -1,18 +1,37 @@ - name: Test if user phd already exists - command: test -f ~/.profile -a -f ~/.shellrc - failed_when: false - 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: - - name: Create user phd - import_tasks: create.yml + - 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: Upload and extract home archive 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