ansible的应用yaml语言

1.dns的地址 vim /etc/resolve.conf

2.ansible服务器   /etc/hosts

192.168.127.128 ansible

192.168.127.129 host1

192.168.127.134 host2

192.168.127.139 host3

192.168.127.140 host4

vim /etc/ansible/hosts

[webserver]

host1

host2

host3

host4

[apache]

host[1:2]

[nginx]

host[3:4]

[webserver:children]

apache

nginx

[webserver:vars]

ansible_ssh_user='root'

ansible_ssh_pass='666666'

ansible_ssh_port='2222'

yum -y install epel-release

yum -y install ansible

ssh-keygen

ssh-copy-id  IP地址

ansible localhost -m ping

ansible nginx -m ping -u root -k -o

ansible apache -m ping -u root -k -o

去掉yes/no 

vim  /etc/ssh/ssh_config

StrictHostKeyChecking no

systemctl restart sshd

ansible host2 -m ping -u root -k -o  未设置免密

[webserver]
host1 ansible_ssh_user='root' ansible_ssh_pass='777777' ansible_ssh_port='2222'
host[2:4] ansible_ssh_user='root' ansible_ssh_pass='666666'

修改端口号

vim /etc/ssh/sshd_config

Port 2222

systemctl restart sshd

vim /etc/ansible/hosts

[webserver]
host[1:4]
[webserver:vars]
ansible_ssh_user='root'
ansible_ssh_pass='666666'

[apache]
host[1:2]
[nginx]
host[3:4]
[webserver:children]
apache
nginx
[webserver:vars]
ansible_ssh_user='root'
ansible_ssh_pass='666666'

vim hostlist  

[dockers]
host1
host2
[dockers:vars]
ansible_ssh_user='root'
ansible_ssh_pass='666666'

ansible -i  hostlist dockers  -m ping  -o

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值