2023-02-20 11:12:57 +00:00
|
|
|
- hosts: demo
|
|
|
|
gather_facts: no
|
|
|
|
tasks:
|
|
|
|
- name: Test privileged account
|
|
|
|
ansible.builtin.ping:
|
|
|
|
|
|
|
|
- name: Change password
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: "{{ account.username }}"
|
|
|
|
password: "{{ account.secret | password_hash('des') }}"
|
|
|
|
update_password: always
|
2023-05-19 08:09:32 +00:00
|
|
|
ignore_errors: true
|
2023-03-08 10:52:00 +00:00
|
|
|
when: account.secret_type == "password"
|
2023-02-20 11:12:57 +00:00
|
|
|
|
|
|
|
- name: create user If it already exists, no operation will be performed
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: "{{ account.username }}"
|
2023-03-08 10:52:00 +00:00
|
|
|
when: account.secret_type == "ssh_key"
|
2023-02-20 11:12:57 +00:00
|
|
|
|
|
|
|
- name: remove jumpserver ssh key
|
|
|
|
ansible.builtin.lineinfile:
|
2023-04-13 11:02:04 +00:00
|
|
|
dest: "{{ ssh_params.dest }}"
|
|
|
|
regexp: "{{ ssh_params.regexp }}"
|
2023-02-20 11:12:57 +00:00
|
|
|
state: absent
|
|
|
|
when:
|
2023-03-08 10:52:00 +00:00
|
|
|
- account.secret_type == "ssh_key"
|
2023-04-13 11:02:04 +00:00
|
|
|
- ssh_params.strategy == "set_jms"
|
2023-02-20 11:12:57 +00:00
|
|
|
|
|
|
|
- name: Change SSH key
|
|
|
|
ansible.builtin.authorized_key:
|
|
|
|
user: "{{ account.username }}"
|
|
|
|
key: "{{ account.secret }}"
|
2023-04-13 11:02:04 +00:00
|
|
|
exclusive: "{{ ssh_params.exclusive }}"
|
2023-03-08 10:52:00 +00:00
|
|
|
when: account.secret_type == "ssh_key"
|
2023-02-20 11:12:57 +00:00
|
|
|
|
|
|
|
- name: Refresh connection
|
|
|
|
ansible.builtin.meta: reset_connection
|
|
|
|
|
|
|
|
- name: Verify password
|
|
|
|
ansible.builtin.ping:
|
|
|
|
become: no
|
|
|
|
vars:
|
|
|
|
ansible_user: "{{ account.username }}"
|
|
|
|
ansible_password: "{{ account.secret }}"
|
|
|
|
ansible_become: no
|
2023-03-08 10:52:00 +00:00
|
|
|
when: account.secret_type == "password"
|
2023-02-20 11:12:57 +00:00
|
|
|
|
|
|
|
- name: Verify SSH key
|
|
|
|
ansible.builtin.ping:
|
|
|
|
become: no
|
|
|
|
vars:
|
|
|
|
ansible_user: "{{ account.username }}"
|
|
|
|
ansible_ssh_private_key_file: "{{ account.private_key_path }}"
|
|
|
|
ansible_become: no
|
2023-03-08 10:52:00 +00:00
|
|
|
when: account.secret_type == "ssh_key"
|