系統centos7.3
ip位址192.168.1.10
[安裝ansible]
yum install epel-release -y
yum install ansible -y
[SSH部分]
#配置ssh免密碼登陸,若是用普通使用者請在普通使用者下建立SSH密鑰.且ssh統一使用一個賬号.
ssh-keygen -t rsa 預設下一步即可.
#複制密鑰到需要ssh的機器.
ssh-copy-id -i #預設會把密鑰放入對端機器的/root/.ssh/authorized_keys
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 列出所有的子產品
本文轉自 一招拜師 51CTO部落格,原文連結:http://blog.51cto.com/sadoc/1941811