系統centos7.3linux
ip地址192.168.1.10nginx
[安裝ansible]centos
yum install epel-release -yssh
yum install ansible -yide
[SSH部分]centos7
#配置ssh免密碼登錄,如果用普通用戶請在普通用戶下建立SSH密鑰.且ssh統一使用一個帳號.日誌
ssh-keygen -t rsa 默認下一步便可.ip
#複製密鑰到須要ssh的機器.rem
ssh-copy-id -i #默認會把密鑰放入對端機器的/root/.ssh/authorized_keysit
ssh-copy-id -i ~/.ssh/id_rsa.pub 192.168.1.11:
[Ansible配置部分]
1.[默認以下]
[root@centos7 ~] ll /etc/ansible
total 24
-rw-r--r--. 1 root root 18064 Jun 26 07:28 ansible.cfg 主配置文件
-rw-r--r--. 1 root root 1038 Jun 26 07:09 hosts 存放遠程主機配置
drwxr-xr-x. 2 root root 6 Jun 2 05:49 roles roles目錄
2.[修改主配置文件]
[root@centos7 ~]# grep -v "#\|^$" /etc/ansible/ansible.cfg
[defaults]
inventory = /etc/ansible/hosts #主機文件
remote_tmp = ~/.ansible/tmp
local_tmp = ~/.ansible/tmp
ask_sudo_pass = True #開啓是否用sudo密碼
ask_pass = True #開啓這個每次操做須要ssh密碼如果免密碼則取消
remote_port = 22
timeout = 10
log_path = /var/log/ansible.log #存放日誌文件
3.[添加客戶端(節點)]----ip:192.168.1.11
[root@centos7 ~] grep "linux\|192.168.1.11" /etc/ansible/hosts
[linux] 組名
192.168.1.11 組下節點IP
4.[Ansible簡單操做]
#-----ansible linux -m yum -a 'name=nginx'
#-----linux也能夠直接ip地址
-m 模塊
-a 須要的指令
ansible-doc -l 列出全部的模塊