]> git.phdru.name Git - ansible.git/blob - playbooks/roles/phd/tasks/main.yml
Feat: Improve task names
[ansible.git] / playbooks / roles / phd / tasks / main.yml
1 - name: Test if user phd already exists
2   stat:
3     path: "{{ item }}"
4   register: phd_exists
5   changed_when: not phd_exists.stat.exists
6   loop: ['~/.profile', '~/.shellrc']
7
8 - debug:
9     msg: "User phd has already been created"
10   when: phd_exists.results|selectattr('stat.exists')|list|length == 2
11
12 - name: Create and setup user phd
13   block:
14     - name: Create system groups
15       become: true
16       group:
17         name: "{{ item }}"
18         system: true
19       loop: "{{ system_groups.split(',') }}"
20
21     - name: Create group phd
22       become: true
23       group:
24         name: phd
25
26     - name: Add user phd
27       become: true
28       user:
29         name: phd
30         group: phd
31         groups: "{{ system_groups }}"
32
33     - name: Remove default mc directories
34       file:
35         path: "{{ item }}"
36         state: absent
37       loop: ['~/.cache/mc', '~/.config/mc', '~/.local/share/mc']
38
39     - name: Upload and extract home archive
40       unarchive:
41         src: ~/archive/STORE/phd/Home/phd.tar.bz2
42         dest: /home
43       register: phd_extracted
44       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]))"
45
46     - name: Add alias (Debian)
47       become: true
48       lineinfile:
49         path: /etc/aliases
50         regexp: "^root: phd$"
51         line: "root: phd"
52       when: ansible_facts.os_family == 'Debian'
53   when: phd_exists.results|selectattr('stat.exists')|list|length != 2
54
55 - name: Add alias (RedHat)
56   become: true
57   lineinfile:
58     path: /etc/aliases
59     regexp: "^root:             phd$"
60     line: "root:                phd"
61   when: ansible_facts.os_family == 'RedHat'