ansible自动化运维01

mac linux ansible的使用

安装

brew install ansible
[centos]
yum install ansible

新建默认配置文件路径

mkdir /etc/ansible
cd /etc/ansible
vi ansible.cfg
vi host

ansible.cfg 示例

[defaults]
inventory = /etc/ansible/hosts 
forks = 5 #设置默认情况下Ansible最多能有多少个进程同时工作,默认设置最多5个进程并行处理。
default_sudo_user = root
host_key_checking = False
#log_path = /var/log/ansible.log 
private_key_file = /Users/andy/.ssh/id_rsa #本地密钥存放路径
[ssh_connection]
ssh_args = -o StrictHostKeyChecking=no

hosts 示例

Ansible执行命令常用Option

ansible aliyun  -m command -a "echo hello"

ad-hoc 用法

ansible app -m pip -a "name=django state=present"
ansible 192.168.10.10 -m conmand -a "service ntpd status"
用:作分隔符,指定多台机器做变更
ansible 192.168.10.10:192.168.10:20 -m conmand -a "service ntpd status"

playbook 用法