Ansible use (a)

Basic Configuration

安装
yum install ansible -y

修改配置
vim /etc/ansible/hosts

#-不分组
192.168.56.103

#-分组
[web1]
192.168.56.104
192.168.56.105

[web]
192.168.56.101

# 如果配有SSH信任证书,则无需加K, 使用sudo,则加 -u ansible -sudo
ansible web主机名(单/组) -m ping -k   
ansible web1 -m ping -k  
+++++++++++++++++++++++++++++++++
第一次配置
首先,需要关闭 对方的防火墙
systemctl stop firewalld.service
其次,ssh一次,yes,成功连接
然后再次执行,就会成功啦
+++++++++++++++++++++++++++++++++


配置SSH无密码访问
为了避免每次都输入密码
ssh-keygen -t rsa
疯狂回车
cd /root/.ssh
id_rsa私钥  id_rsa.pub公钥(下发到被控制主机.ssh目录,命名为authorized_keys)
+++++++++++++++++++++++++++++++++++
或者执行
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
# 再次ping 无需密码
ansible web主机名(单/组) -m ping
+++++++++++++++++++++++++++++++++++

Briefly recognize
the use of the ansible

Remote command module

# 远程执行命令
ansible web -m command -a "ifconfig"

# 远程执行本机的脚本、其实是scp+shell,远程不会留下脚本
ansible web -m script -a "/root/aaa.sh"

# 远程执行 远端服务器脚本
ansible web -m script -a "/root/aaa.sh"

Other modules

https://blog.csdn.net/sunt2018/article/details/90902857

Guess you like

Origin blog.csdn.net/sunt2018/article/details/90902826