Ansible簡單安裝

系統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 列出所有的模塊

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章