Ansible可以完成哪些任务
Ansible特点
Ansible安装方式
python pip安装
优点
软件源安装
优点
软件源安装(ubuntu)
优点
Ansible配置
host配置
host文件: /etc/ansible/hosts
配置内容:
[test]
192.168.1.1
配置远程登录
添加公钥:
ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.1.1
连通测试
运行Ansible命令:
ansible all -m ping
正确的运行结果:
192.168.1.1 | SUCCESS => {
? "changed": false,
? "ping": "pong"
}
Ad-hoc怎么用
举例说明:
列出目标主机目录
ansible test -m shell -a "ls /root" --user=root
Ansible help message
Inventory是什么
Inventory主机组
[组名]
192.168.1.1
192.168.1.2
Inventory主机别名
jumper ansible_ssh_port = 22
ansible_ssh_host = 192.168.1.1
Inventory链接参数
ansible_ssh_host
#将要连接的远程主机名,与你想要设定的主机别名不同的话,可通过此变量设置
ansible_ssh_port
#ssh端口号,如果不是默认的端口号,通过此变量设置
ansible_ssh_user
#默认的ssh用户吗
ansible_ssh_pass
#ssh密码(这种方式并不安全,我们强烈建议使用 --ask-pass或SSH)
ansible_sudo_pass
#sudo密码(这种方式并不安全,我们强烈建议使用 --ask-sudo-pass)
[websevers]
www[01:50].example.com
[databases]
db-[a:f].example.com
实战
安装mysql
ansible test -m yum -a "name=mariadb-server state=latest"
#安装使用yum模块 name参数是必须的,服务名称, state参数是可选的,latest表示安装
启动服务/暂停服务
ansible test -m systemd -a "name=mariadb state=started"
#启动mariadb服务
ansible test -m systemd -a "name=mariadb state=stopped"
#关闭mariadb服务
查看mysql服务是否启动
ansible test -m shell -a "ps -ef|grep mysql"
原文:https://www.cnblogs.com/only-me/p/11426135.html