]> git.phdru.name Git - ansible.git/blobdiff - playbooks/roles/phd/tasks/main.yml
Feat: Combine Debian/RedHat playbooks and roles
[ansible.git] / playbooks / roles / phd / tasks / main.yml
diff --git a/playbooks/roles/phd/tasks/main.yml b/playbooks/roles/phd/tasks/main.yml
new file mode 100644 (file)
index 0000000..cb36caa
--- /dev/null
@@ -0,0 +1,59 @@
+- 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 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
+
+    - name: Add alias
+      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
+  become: true
+  lineinfile:
+    path: /etc/aliases
+    regexp: "^root:            phd$"
+    line: "root:               phd"
+  when: ansible_facts.os_family == 'RedHat'