--- /dev/null
+- 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: 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: Create folder ~phd/.ssh
- file:
- path: ~phd/.ssh
- state: directory
- owner: phd
- group: phd
- mode: 0700
-- name: Upload SSH key
- copy:
- src: ~/.ssh/phd@nb3.pub
- dest: ~phd/.ssh/authorized_keys
- owner: phd
- group: phd
- mode: 0600
+- name: Test if user phd already exists
+ command: test -f ~/.profile -a -f ~/.shellrc
+ ignore_errors: true
+ register: phd_exist
+
+- debug:
+ msg: "User phd has already been created"
+ when: phd_exist.rc == 0
+
+- name: "Create and setup user phd"
+ block:
+ - name: "Create user phd"
+ import_tasks: create.yml
+ - name: "Setup SSH: copy SSH public key"
+ import_tasks: setup-ssh.yml
+ when: phd_exist.rc != 0
--- /dev/null
+- name: Create folder ~phd/.ssh
+ file:
+ path: ~phd/.ssh
+ state: directory
+ owner: phd
+ group: phd
+ mode: 0700
+
+- name: Upload SSH key
+ copy:
+ src: ~/.ssh/phd@nb3.pub
+ dest: ~phd/.ssh/authorized_keys
+ owner: phd
+ group: phd
+ mode: 0600