2022-10-09 12:54:11 +00:00
|
|
|
- hosts: demo
|
2022-10-10 05:56:42 +00:00
|
|
|
gather_facts: no
|
2022-10-09 12:54:11 +00:00
|
|
|
tasks:
|
|
|
|
- name: Test privileged account
|
2022-10-14 08:33:24 +00:00
|
|
|
ansible.builtin.ping:
|
|
|
|
#
|
|
|
|
# - name: print variables
|
|
|
|
# debug:
|
|
|
|
# msg: "Username: {{ account.username }}, Secret: {{ account.secret }}, Secret type: {{ account.secret_type }}"
|
2022-10-09 12:54:11 +00:00
|
|
|
|
|
|
|
- name: Change password
|
2022-10-14 08:33:24 +00:00
|
|
|
ansible.builtin.user:
|
2022-10-09 12:54:11 +00:00
|
|
|
name: "{{ account.username }}"
|
2022-10-13 09:47:29 +00:00
|
|
|
password: "{{ account.secret | password_hash('sha512') }}"
|
2022-10-09 12:54:11 +00:00
|
|
|
update_password: always
|
2022-10-14 08:33:24 +00:00
|
|
|
when: account.secret_type == "password"
|
2022-10-09 12:54:11 +00:00
|
|
|
|
|
|
|
- name: Change public key
|
2022-10-14 08:33:24 +00:00
|
|
|
ansible.builtin.authorized_key:
|
2022-10-09 12:54:11 +00:00
|
|
|
user: "{{ account.username }}"
|
|
|
|
key: "{{ account.public_key }}"
|
|
|
|
state: present
|
2022-10-14 08:33:24 +00:00
|
|
|
when: account.secret_type == "public_key"
|
|
|
|
|
|
|
|
- name: Refresh connection
|
|
|
|
ansible.builtin.meta: reset_connection
|
2022-10-09 12:54:11 +00:00
|
|
|
|
|
|
|
- name: Verify password
|
2022-10-14 08:33:24 +00:00
|
|
|
ansible.builtin.ping:
|
|
|
|
become: no
|
2022-10-09 12:54:11 +00:00
|
|
|
vars:
|
|
|
|
ansible_user: "{{ account.username }}"
|
2022-10-14 08:33:24 +00:00
|
|
|
ansible_password: "{{ account.secret }}"
|
|
|
|
ansible_become: no
|