ansible批量修改密码策略
ansible批量修改密码策略
示例:
主机: 172.16.5.154
主机: 172.16.5.156
主机: 172.16.5.157
在主机172.16.5.154主机上安装ansible
yum -y install epel-release
yum -y install ansible
修改vi /etc/ansible/ansible.cfg配置文件
将# host_key_checking = False改为host_key_checking = False
在主机172.16.5.154上生成自己的密钥
ssh-keygen -N '' -f ~/.ssh/id_rsa
mkdir tao
cd tao
cat host.ini
内容如下
[test]
172.16.5.154
172.16.5.156
172.16.5.157
7 | cat foo.yml
内容如下
ansible_ssh_pass: password123@
cat send-pubkey.yml
内容如下
---
- name: copyhosts: allgather_facts: noremote_user: rootvars_files:- foo.ymltasks:- name: Set authorized key taken from fileauthorized_key: user: root state: presentkey: "{{ lookup('file', '/root/.ssh/id_rsa.pub') }}"- name: backup before sshdcopy: src: /etc/pam.d/sshddest: /etc/pam.d/sshd.bak- name: copy:src: /etc/pam.d/logindest: /etc/pam.d/login.bak- name: backup before system-authcopy: src: /etc/pam.d/system-authdest: /etc/pam.d/system-auth.bak- name: add content to sshd lineinfile:path: '/etc/pam.d/sshd'insertafter: '^#%PAM-1.0'line: 'auth required pam_tally2.so onerr=fail deny=3 unlock_time=300 even_deny_root root_unlock_time=300'- name: add content to loginlineinfile:path: '/etc/pam.d/login'insertafter: '^#%PAM-1.0'line: 'auth required pam_tally2.so onerr=fail deny=3 unlock_time=300 even_deny_root root_unlock_time=300'- name: deletereplace:path: /etc/pam.d/system-authregexp: '^password.*3$'replace: "#password requisite pam_cracklib.so retry=5 difok=3 minlen=10 ucredit=-1 lcredit=-3"- name: add content to system-authlineinfile:path: '/etc/pam.d/system-auth'insertbefore: '^password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=' line: 'password requisite pam_cracklib.so retry=3 difok=3 minlen=10 ucredit=-1 lcredit=-2 dcredit=-1 ocredit=-1'
...
执行如下命令:
ansible-playbook -i host.ini send-pubkey.yml
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
