Playbook 介绍
Playbook是 一个不同于使用Ansible命令行执行方式的模式,其功能更强大灵活。简单来说,playbook是一个非常简单的配置管理和多主机部署系统,不同于任何已经存在的模式,可作为一个适合部署复杂应用程序的基础。Playbook可以定制配置,可以按照指定的操作步骤有序执行,支持同步和异步方式。值得注意的是playbook是通过YAML格式来进行描述定义的。
1、目前两台服务器的主机名:
192.168.20.40
[root@docker02 ~]# hostname
docker02
192.168.20.39
[root@slavedb tmp]# hostname
slavedb
2、Ansible配置
root@docker02 ~]# vim /etc/ansible/hosts
[all]
k8s-master ansible_ssh_host=192.168.20.40
k8s-node3 ansible_ssh_host=192.168.20.39
3、创建playbook脚本
[root@k8s-master ~]# more passwd.yml
---
- hosts: all
tasks:
- name: change passwd
user: name={{ item.user }} password={{ item.password | password_hash('sha512') }} update_password=always
with_items:
- { user: 'root', password: '123456' }
register: result
- debug: var=result
4、运行playbook脚本
[root@k8s-master ~]# ansible-playbook passwd.yml
"item": {
"password": "123456",
"user": "root"
},
"move_home": false,
"name": "root",
"password": "NOT_LOGGING_PASSWORD",
"shell": "/bin/bash",
"state": "present",
"uid": 0
}
5、重新登录服务器,是否有提示密码更新
Connecting to 192.168.20.40:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
WARNING! The remote SSH server rejected X11 forwarding request.
Last failed login: Fri Jan 22 09:08:12 EST 2021 from 192.168.20.7 on ssh:notty
There were 2 failed login attempts since the last successful login.
Last login: Fri Jan 22 09:04:30 2021 from docker02
相关阅读:
1、实战--Playbook批量部署zabbix-agent
4、欢迎加入技术交流
欢迎加入QQ技术交流群:653256902,请分享到朋友圈让更多的关注,共同学习进步!