ansible安装使用

安装ansible

[root@zhaikaiyun ~]#yum install ansible -y
[root@zhaikaiyun ~]# cd /etc/ansible/
[root@zhaikaiyun ansible]# ll
total 20
-rw-r--r-- 1 root root 14396 Nov 11 09:37 ansible.cfg
-rw-r--r-- 1 root root  1016 Nov 11 09:37 hosts
drwxr-xr-x 2 root root     6 Nov 11 09:37 roles

修改ansible.cfg

# uncomment this to disable SSH key host checking
#host_key_checking = False去除#,解决首次登陆失败的问题

# change the default callback
#stdout_callback = skippy
# enable additional callbacks
#callback_whitelist = timer, mail

配置机器

在ansible.cfg末尾加上操作主机的用户
[self]
192.168.1.20 ansible_ssh_user=zhaiky ansible_ssh_pass=123456 ansible_become_pass=123456
192.168.1.21 ansible_ssh_user=zhaiky ansible_ssh_pass=123456 ansible_become_pass=123456
 

常规使用
ansible csfzk -m shell  -a 'echo "ok"'

你可能感兴趣的:(linux)