wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3、Ansible的配置文件,配置文件可疑随意放,但有查找顺序
[root@wld-01-71 ~]# cat /etc/ansible/ansible.cfg
#inventory = /etc/ansible/hosts #主机列表配置文件
#library = /usr/share/my_modules/ #库文件存放目录
#remote_tmp = ~/.ansible/tmp #临时py文件存放在远程主机目录
#local_tmp = ~/.ansible/tmp #本机的临时执行目录
#ask_sudo_pass = True #每次执行是否询问sudo的ssh密码
#ask_pass = True #每次执行是否询问ssh密码
host_key_checking =False #跳过检查主机指纹
log_path = /var/log/ansible.log #ansible日志
[privilege_escalation] #如果是普通用户则需配置提权
--------------------------------------------------------------------------------------------------------
场景二、基于密钥链接,需要先创建公钥和私钥,并下发公钥至被控端
[root@wld-01-71 .ssh]# ssh-keygen
[root@wld-01-71 .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
[root@wld-01-71 .ssh]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
---------------------------------------------------------------------------------------------------------
192.168.1.72或192.168.1.72:8888(不是22端口的)
[root@wld-01-71 ~]# ansible webservers -m ping -i ./hosts
web01 ansible_ssh_host=192.168.1.72 ansible_ssh_port=22
web01 ansible_ssh_host=192.168.1.73 ansible_ssh_port=22
[root@wld-01-71 ~]# ansible webservers1 -m ping -i ./hosts
---------------------------------------------------------------------------------------------------
[root@wld-01-71 ~]# ansible webservers -m ping -i ./hosts --list-hosts
#2、servers组包括两个子组[webservers,lbservers]
web01 ansible_ssh_host=192.168.1.72 ansible_ssh_port=22
web02 ansible_ssh_host=192.168.1.73 ansible_ssh_port=22
[root@wld-01-71 ~]# ansible servers -m ping -i ./hosts --list-hosts
[root@wld-01-71 ~]# ansible all -m ping -i ./hosts --list-hosts
--------------------------------------------------------------------------------------------------------------------------