본문 바로가기

리눅스

[Ansible] 계정 생성 및 삭제

반응형

ANSIBLE 계정 생성 및 삭제

 

ansible -m command -a "cat /etc/passwd" mongodb | grep devops5

1. 계정 생성

ansible-playbook --ask-pass -u root a_useradd.yml
$ ansible-playbook --ask-pass -u root a_useradd.yml
SSH password:

Output---

PLAY [192.168.56.111,192.168.56.112,192.168.56.113] ****************************

TASK [setup] *******************************************************************
ok: [192.168.56.111]
ok: [192.168.56.112]
ok: [192.168.56.113]

TASK [new account] *************************************************************
changed: [192.168.56.112]
changed: [192.168.56.113]
changed: [192.168.56.111]

PLAY RECAP *********************************************************************
192.168.56.111             : ok=2    changed=1    unreachable=0    failed=0
192.168.56.112             : ok=2    changed=1    unreachable=0    failed=0
192.168.56.113             : ok=2    changed=1    unreachable=0    failed=0
ansible -m command -a "cat /etc/passwd" mongodb | grep devops5
$  ansible -m command -a "cat /etc/passwd" mongodb | grep devops5
...
devops5:x:501:501::/home/devops5:/bin/bash
devops5:x:501:501::/home/devops5:/bin/bash
devops5:x:501:501::/home/devops5:/bin/bash

2. 계정 삭제

ansible-playbook --ask-pass -u root a_userdel.yml
$ ansible-playbook --ask-pass -u root a_userdel.yml
SSH password:
...
PLAY [192.168.56.111,192.168.56.112,192.168.56.113] ****************************

TASK [setup] *******************************************************************
ok: [192.168.56.111]
ok: [192.168.56.113]
ok: [192.168.56.112]

TASK [new account] *************************************************************
changed: [192.168.56.113]
changed: [192.168.56.112]
changed: [192.168.56.111]

PLAY RECAP *********************************************************************
192.168.56.111             : ok=2    changed=1    unreachable=0    failed=0
192.168.56.112             : ok=2    changed=1    unreachable=0    failed=0
192.168.56.113             : ok=2    changed=1    unreachable=0    failed=0
ansible -m command -a "cat /etc/passwd" mongodb | grep devops5

 

vi a_useradd.yml
---
- hosts: 192.168.56.111,192.168.56.112,192.168.56.113
  remote_user: root
  vars:
    USER_NAME: 'devops5'
  tasks:
    - name: "new account"
      user: name={{ USER_NAME }}
            password='$6$r8QrZkp/$nyrCAy3TQVrnHOO7wn0cAhqpgsJUnOOo1r9OLwhjPSaUzEP6yvYNXVC/QR.lLPMZc3bcf3A1Az2QjUsXpWIv41'
            #password : P@ssw0rd
vi a_userdel.yml
---
- hosts: 192.168.56.111,192.168.56.112,192.168.56.113
  remote_user: root
  vars:
    USER_NAME: 'devops5'
  tasks:
    - name: "new account"
      user: name={{ USER_NAME }}
            state=absent
            remove=yes
            force=yes

 

728x90
반응형