change password with ansible

ansible을 이용하여 agent 서버의 유저 패스워드 변경

1. 환경준비
    Centos 7.x
    Ansible 

2. env ansible
[root@localhost ~]# vi /etc/ansible/hosts
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
#   - Comments begin with the '#' character
#   - Blank lines are ignored
#   - Groups of hosts are delimited by [header] elements
#   - You can enter hostnames or ip addresses
#   - A hostname/ip can be a member of multiple groups

[testgroup]
#192.168.0.156 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxxx
192.168.0.194 ansible_connection=ssh ansible_ssh_user=min ansible_ssh_pass=xxxxxxx

# edit playbook
[root@localhost ~]# vi changepw.yml
- hosts: testgroup
  tasks:
  - name: Test echo
    shell:
      whoami
      echo -e 'oldpassword1\nlinuxpassword2\nlinuxpassword2' | passwd 
    register: cat
  - debug: var=cat.stdout_lines
    

3. excute ansible
[root@localhost ~]# ansible-playbook changepw.yml

PLAY [testgroup] *******************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [192.168.0.194]

TASK [Test echo] *******************************************************************************************************
fatal: [192.168.0.194]: FAILED! => {"changed": true, "cmd": "whoami echo -e 'oldpassword1\\nlinuxpassword2\\nlinuxpassword2'        | passwd", "delta": "0:00:01.807548", "end": "2019-07-08 23:42:12.918473", "msg": "non-zero return code", "rc": 1, "sta       rt": "2019-07-08 23:42:11.110925", "stderr": "whoami: 부적절한 옵션 -- 'e'\nTry 'whoami --help' for more information.\n(       현재) UNIX 암호:passwd: 인증 토근 수정 오류", "stderr_lines": ["whoami: 부적절한 옵션 -- 'e'", "Try 'whoami --help' for        more information.", "(현재) UNIX 암호:passwd: 인증 토근 수정 오류"], "stdout": "testuser 사용자의 비밀 번호 변경 중\ntes       tuser에 대한 암호 변경 중  ", "stdout_lines": ["testuser 사용자의 비밀 번호 변경 중", "testuser에 대한 암호 변경 중  "]}

PLAY RECAP *************************************************************************************************************
192.168.0.194              : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0









댓글

이 블로그의 인기 게시물

[!] CDN: trunk URL couldn't be downloaded: https://cdn.cocoapods.org/CocoaPods-version.yml Response: URL using bad/illegal format or missing URL

starcraft map

Data Analysis with Superset - boardless chart