AKAI TSUKI

System development or Technical something

create user by ansible playbook.

To create user repeatedly, ansible is useful.
I create playbook for password authorization.

[root@cent7devops ansible-test]# cat ./hosts
[grp_node]
node01 ansible_host=172.16.10.111 ansible_user=root
node02 ansible_host=172.16.10.112 ansible_user=root
node03 ansible_host=172.16.10.113 ansible_user=root
[root@cent7devops ansible-test]#

ope_pass variable is defined as a password for "opeuser".

[root@cent7devops ansible-test]# cat create_user.yml
---
- name: user manage
  hosts: grp_node
  tasks:
  - name: Add the user
    user:
      name: opeuser
      password: "{{ ope_pass|password_hash('sha512') }}"

[root@cent7devops ansible-test]#

I'd like to execute ansible for only "node01" host. I use "-l node01" option.

[root@cent7devops ansible-test]# ansible-playbook -i hosts create_user.yml --vault-id ./vault.txt -l node01