main.yml 676 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
- name: "Ensure required parameters provided"
  assert:
    that: 
      - username != ""
      - default_password != ""
      - authorized_ssh_key != ""
    msg: "Please provide the required parameters!"

- name: Block w/ 'become' escalation
  block:
    - name: Create new sudo user
      user:
        name: "{{ username }}"
        password: "{{ default_password|password_hash('sha512') }}"
        create_home: yes
        groups: sudo
Florian Kempenich's avatar
Florian Kempenich committed
17
        shell: /bin/zsh
18
19
20
21
22
23
24
25
26
        update_password: on_create

    - name: "Add SSH key to autorized_keys"
      authorized_key:
        user: "{{ username }}"
        key: "{{ authorized_ssh_key }}"
        state: present
  become: yes