--ansible安裝
yum -y install ansible
如果無法安裝忧陪,先安裝前置
[root@arthur ~]# yum install epel-release
[root@arthur ~]# yum repolist
[root@arthur ~]# yum -y install ansible
免秘鑰登陸
[root@martin-1 ~]#? ssh-keygen? -t? rsa
[root@martin-1 ~]#? ssh-copy-id? -i? /root/.ssh/id_rsa.pub? 192.168.106.129
[root@martin-1 ~]#? ssh-copy-id? -i? /root/.ssh/id_rsa.pub? 192.168.106.130
為Ansible定義節(jié)點(diǎn)的清單
文件/etc/ansible/hosts 維護(hù)著Ansible中服務(wù)器的清單。
[root@ansible ~]# vi /etc/ansible/hosts
[vm]
192.168.106.129 name pasword
192.168.106.130
保存并退出文件赡突。
嘗試在Ansible服務(wù)端運(yùn)行命令
使用ping檢查‘test-servers’或者ansible節(jié)點(diǎn)的連通性。
[root@ansible ~]# ansible -m ping 'vm'
執(zhí)行shell命令
1:檢查Ansible節(jié)點(diǎn)的運(yùn)行時(shí)間(uptime)
[root@ansible ~]# ansible -m command -a "uptime" 'vm'
2:檢查節(jié)點(diǎn)的內(nèi)核版本
[root@ansible ~]# ansible -m command -a "uname -r" 'vm'
打開日志
修改:ansible.cfg文件(默認(rèn)路路徑為/etc/ansible/ansible.cfg)
#log_path = /var/log/ansible.log(取消注釋颜骤,值為默認(rèn)日志存放地點(diǎn))
play_book
創(chuàng)建yaml文件
vim testVault
- hosts: test
vars:
remote_user: root
tasks:
- name: write the apache config file
template: src=/tmp/1.txt dest=/tmp
執(zhí)行ansible-playbook testVault
Playbook擴(kuò)展--使用參數(shù)和加密
vim testVault
- hosts: test
vars_files:
- vars/files.yml
remote_user: root
tasks:
- name: write the apache config file
template: src=/tmp/{{ file_name }} dest=/tmp
vim files.yml
---
file_name: '2.txt'
ansible-playbook testfile.yml --ask-vault-pass
輸入密碼即可