ansible基础
注意:需要有python环境
yum -y install ansibel
查看ansible版本:
ansible --version
ansible 2.9.25
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible
python version = 2.7.5 (default, Apr 2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
注意在/etc/hosts中做好域名解析
vim /etc/ansible/hosts
[webserver]
host1 #主机名称
host2
host3
#涉及端口/密码/用户名
[webserver]
host1
host2
host3
#变量
[webserver:vars]
ansible_ssh_user='test' #用户名
ansible_ssh_port='9347' #端口
ansible_ssh_pass='******' #密码
#主机密码/端口/用户名不同时,要分开写
[webserver]
host1 ansible_ssh_user='test' ansible_ssh_pass='******'
host[2:4] ansible_ssh_user='login' ansible_ssh_pass='******'
#将不同的变量进行组合
[apache]
host[1:2]
[nginx]
host[3:4]
[webserver:children]
apache
nginx
[webserver:vars]
ansible_ssh_user='test'
ansible_ssh_pass='******'
#普通账户提权
ansible_become=true
ansible_become_method=sudo
ansible_become_user=root
ansible webserver -m ping -o
gitlab-server | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "ping": "pong"}
tengxun-server | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "ping": "pong"}
ftp-server | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "ping": "pong"}