-
1、執(zhí)行一個(gè)長時(shí)間的任務(wù)、
[root@centos7 ~]# ansible test -B 60 -P 1 -a "sleep 70"
10.16.168.103 | FAILED | rc=-1 >>
async task did not complete within the requested time
10.16.168.104 | FAILED | rc=-1 >>
async task did not complete within the requested time
2、獲取jid
[root@centos7 ~]# ansible test -a "ls /root/.ansible_async"
10.16.168.103 | CHANGED | rc=0 >>
921373620331.20393
921373620331.20393.tmp
10.16.168.104 | CHANGED | rc=0 >>
925556219979.18065
925556219979.18065.tmp
3、通過獲取的jid、拿執(zhí)行的狀態(tài)、test[0]、test組中第一個(gè)主機(jī)、和python列表取值一樣、也可以切片、
[root@centos7 ~]# ansible test[0] -m async_status -a "jid=921373620331.20393"
10.16.168.103 | SUCCESS => {
? ? "ansible_job_id": "921373620331.20393",?
? ? "changed": false,?
? ? "finished": 0,?
? ? "started": 1
}
[root@centos7 ~]# ansible test[1] -m async_status -a "jid=925556219979.18065"
10.16.168.104 | SUCCESS => {
? ? "ansible_job_id": "925556219979.18065",?
? ? "changed": false,?
? ? "finished": 0,?
? ? "started": 1
}
查看全部 -
webservers:nginx:&vim:!python:!mysql webservers和nginx2個(gè)組中的所有主機(jī)、同時(shí)還要在vim組中、但不在python和mysql組中的主機(jī)、 驗(yàn)證hosts文件入下、 [webservers] 1.1.1.1 1.1.1.2 1.1.1.3 [nginx] 1.1.1.1 1.1.1.4 1.1.1.5 1.1.1.6 1.1.1.7 [vim] 1.1.1.2 1.1.1.6 [python] 1.1.1.3 1.1.1.6 [mysql] 1.1.1.4 1.1.1.7
NOTE: 超過2個(gè)匹配邏輯判斷時(shí)要用引號(hào)引起來、有!非邏輯時(shí)、要用單引號(hào)把!當(dāng)成普通字符、""會(huì)報(bào)錯(cuò):-bash: !python": event not found、
如上的hosts文件的結(jié)果為:
[root@centos7 ~]# ansible 'webserver:nginx:&vim:!python:!mysql' --list-hosts
? hosts (1):
? ? 1.1.1.2
符合猜想、
查看全部 -
centos7.6 64位
ansible 2.7.8
python 2.7.5
控制端ip:10.16.168.103
被控端ip:? 10.16.168.104
1、添加控制主機(jī)、
[root@centos7 ~]# cat /etc/ansible/hosts
10.16.168.103
10.16.168.104
2、ansible控制端端生成秘鑰對(duì)、
[root@centos7 ~]# ssh-keygen
3、將公鑰復(fù)制到被控端、
[root@centos7 ~]# ssh-copy-id 10.16.168.103
[root@centos7 ~]# ssh-copy-id 10.16.168.104
4、執(zhí)行ansible的ping模塊、
[root@centos7 ~]# ansible all -m ping
10.16.168.103 | SUCCESS => {
? ? "changed": false,?
? ? "ping": "pong"
}
10.16.168.104 | SUCCESS => {
? ? "changed": false,?
? ? "ping": "pong"
}
查看全部 -
salt 性能更加高
查看全部 -
nagios配置文件
查看全部 -
ansible命令
查看全部 -
ansible命令格式
查看全部 -
ansible添加機(jī)器
查看全部 -
forks
查看全部 -
ansible配置詳解
查看全部 -
ansible配置文件獲取
查看全部 -
ansible配置文件路徑,優(yōu)先級(jí)從高到低
以上都沒有,按照自己默認(rèn)的配置
查看全部 -
ansible安裝
查看全部 -
ansible安裝
查看全部 -
Master節(jié)點(diǎn)和minion不要再同一個(gè)服務(wù)器上,否則會(huì)提示錯(cuò)誤查看全部
舉報(bào)