-B SECONDS, --background SECONDS
run asynchronously, failing after X seconds
(default=N/A)
-P POLL_INTERVAL, --poll POLL_INTERVAL
set the poll interval if using -B (default=15)
-f FORKS, --forks FORKS
specify number of parallel processes to use
(default=5)
-B 后台异步执行 -P隔多长时间检查一下 -f 一次启动几个进程并发执行
使用ansible的-vvv
或-vvvv
分析执行过程。以下是一个启动远程192.168.100.61上httpd任务的执行过程分析。其中将不必要的信息都是用"....."替换了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# 读取配置文件,然后开始执行对应的处理程序。
Using /etc/ansible/ansible.cfg as config file META: ran handlers # 第一个任务默认都是收集远程主机信息的任务。 # 第一个收集任务,加载setup模块 Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/setup.py # 建立连接,获取被控节点当前用户的家目录,用于存放稍后的临时任务文件,此处返回值为/root。 # 在-vvv的结果中,第一行属于描述性信息,第二行为代码执行段,第三行类似此处的>(,,,,,)为上一段代码的返回结果。后同 <192.168.100.61> ESTABLISH SSH CONNECTION FOR USER: None <192.168.100.61> SSH: EXEC ssh -C .......................... <192.168.100.61> (0, '/root\n', '') # 再次建立连接,在远端创建临时任务文件的目录,临时目录由配置文件中的remote_tmp指令控制 <192.168.100.61> ESTABLISH SSH CONNECTION FOR USER: None <192.168.100.61> SSH: EXEC ssh -C .......................... '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202 `" && echo ansible-tmp-1495977564.58-40718671162202="` echo /root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202 `" ) && sleep 0'"'"'' <192.168.100.61> (0, 'ansible-tmp-1495977564.58-40718671162202=/root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202\n', '') # 将要执行的任务放到临时文件中,并使用sftp将任务文件传输到被控节点上 <192.168.100.61> PUT /tmp/tmpY5vJGX TO /root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202/setup.py <192.168.100.61> SSH: EXEC sftp -b - -C ............. '[192.168.100.61]' <192.168.100.61> (0, 'sftp> put /tmp/tmpY5vJGX /root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202/setup.py\n', '') # 建立连接,设置远程任务文件其所有者有可执行权限 <192.168.100.61> ESTABLISH SSH CONNECTION FOR USER: None <192.168.100.61> SSH: EXEC ssh -C ......................... '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202/ /root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202/setup.py && sleep 0'"'"'' <192.168.100.61> (0, '', '') # 建立连接,执行任务,执行完成后立即删除任务文件,并返回收集到的信息给ansible。到此为止,setup收集任务结束,关闭共享连接 <192.168.100.61> ESTABLISH SSH CONNECTION FOR USER: None <192.168.100.61> SSH: EXEC ssh -C ............ '/bin/sh -c '"'"'/usr/bin/python /root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202/setup.py; rm -rf "/root/.ansible/tmp/ansible-tmp-1495977564.58-40718671162202/" > /dev/null 2>&1 && sleep 0'"'"'' <192.168.100.61> (0, '\r\n{"invocation": {"...........', 'Shared connection to 192.168.100.61 closed.\r\n') # 进入下一个任务,此处为服务管理任务,所以加载service模块 Using module file /usr/lib/python2.7/site-packages/ansible/modules/system/service.py # 建立连接,获取被控节点当前用户的家目录,用于存放稍后的临时任务文件,此处返回值为/root <192.168.100.61> ESTABLISH SSH CONNECTION FOR USER: None <192.168.100.61> SSH: EXEC ssh -C ......................... <192.168.100.61> (0, '/root\n', '') # 建立连接,将要执行的任务放入到临时文件中,并传输到远程目录 <192.168.100.61> ESTABLISH SSH CONNECTION FOR USER: None <192.168.100.61> SSH: EXEC ssh -C .............. '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1495977564.97-137863382080241 `" && echo ansible-tmp-1495977564.97-137863382080241="` echo /root/.ansible/tmp/ansible-tmp-1495977564.97-137863382080241 `" ) && sleep 0'"'"'' <192.168.100.61> (0, 'ansible-tmp-1495977564.97-137863382080241=/root/.ansible/tmp/ansible-tmp-1495977564.97-137863382080241\n', '') <192.168.100.61> PUT /tmp/tmpn5uZhP TO /root/.ansible/tmp/ansible-tmp-1495977564.97-137863382080241/service.py <192.168.100.61> SSH: EXEC sftp -b