root@python:~# ansible all -l 10.0.0.15 -m ping -vvv
ansible [core 2.12.2]
config file = /etc/ansible/ansible.cfg
configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python3/dist-packages/ansible
ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
executable location = /usr/bin/ansible
python version = 3.8.10 (default, Jun 2 2021, 10:49:15) [GCC 9.4.0]
jinja version = 2.10.1
libyaml = True
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/hosts inventory source with ini plugin
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
META: ran handlers
<10.0.0.15> ESTABLISH SSH CONNECTION FOR USER: None
<10.0.0.15> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/f2fc772042"' 10.0.0.15 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<10.0.0.15> (0, b'/root\n', b'')
<10.0.0.15> ESTABLISH SSH CONNECTION FOR USER: None
<10.0.0.15> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/f2fc772042"' 10.0.0.15 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302 `" && echo ansible-tmp-1648530223.610464-14686-129290614671302="` echo /root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302 `" ) && sleep 0'"'"''
<10.0.0.15> (0, b'ansible-tmp-1648530223.610464-14686-129290614671302=/root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302\n', b'')
<10.0.0.15> Attempting python interpreter discovery
<10.0.0.15> ESTABLISH SSH CONNECTION FOR USER: None
<10.0.0.15> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/f2fc772042"' 10.0.0.15 '/bin/sh -c '"'"'echo PLATFORM; uname; echo FOUND; command -v '"'"'"'"'"'"'"'"'python3.10'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.9'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.8'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python3.5'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python3'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/libexec/platform-python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.7'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python2.6'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'/usr/bin/python'"'"'"'"'"'"'"'"'; command -v '"'"'"'"'"'"'"'"'python'"'"'"'"'"'"'"'"'; echo ENDFOUND && sleep 0'"'"''
<10.0.0.15> (0, b'PLATFORM\nLinux\nFOUND\n/usr/bin/python3.8\n/usr/bin/python3\nENDFOUND\n', b'')
<10.0.0.15> ESTABLISH SSH CONNECTION FOR USER: None
<10.0.0.15> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/f2fc772042"' 10.0.0.15 '/bin/sh -c '"'"'/usr/bin/python3.8 && sleep 0'"'"''
<10.0.0.15> (0, b'{"platform_dist_result": [], "osrelease_content": "NAME=\\"Ubuntu\\"\\nVERSION=\\"20.04.3 LTS (Focal Fossa)\\"\\nID=ubuntu\\nID_LIKE=debian\\nPRETTY_NAME=\\"Ubuntu 20.04.3 LTS\\"\\nVERSION_ID=\\"20.04\\"\\nHOME_URL=\\"https://www.ubuntu.com/\\"\\nSUPPORT_URL=\\"https://help.ubuntu.com/\\"\\nBUG_REPORT_URL=\\"https://bugs.launchpad.net/ubuntu/\\"\\nPRIVACY_POLICY_URL=\\"https://www.ubuntu.com/legal/terms-and-policies/privacy-policy\\"\\nVERSION_CODENAME=focal\\nUBUNTU_CODENAME=focal\\n"}\n', b'')
Using module file /usr/lib/python3/dist-packages/ansible/modules/ping.py
<10.0.0.15> PUT /root/.ansible/tmp/ansible-local-14682mzr19bf6/tmp5q841i3v TO /root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302/AnsiballZ_ping.py
<10.0.0.15> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/f2fc772042"' '[10.0.0.15]'
<10.0.0.15> (0, b'sftp> put /root/.ansible/tmp/ansible-local-14682mzr19bf6/tmp5q841i3v /root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302/AnsiballZ_ping.py\n', b'')
<10.0.0.15> ESTABLISH SSH CONNECTION FOR USER: None
<10.0.0.15> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/f2fc772042"' 10.0.0.15 '/bin/sh -c '"'"'chmod u+x /root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302/ /root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302/AnsiballZ_ping.py && sleep 0'"'"''
<10.0.0.15> (0, b'', b'')
<10.0.0.15> ESTABLISH SSH CONNECTION FOR USER: None
<10.0.0.15> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/f2fc772042"' -tt 10.0.0.15 '/bin/sh -c '"'"'/usr/bin/python3 /root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302/AnsiballZ_ping.py && sleep 0'"'"''
<10.0.0.15> (0, b'\r\n{"ping": "pong", "invocation": {"module_args": {"data": "pong"}}}\r\n', b'Shared connection to 10.0.0.15 closed.\r\n')
<10.0.0.15> ESTABLISH SSH CONNECTION FOR USER: None
<10.0.0.15> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o 'ControlPath="/root/.ansible/cp/f2fc772042"' 10.0.0.15 '/bin/sh -c '"'"'rm -f -r /root/.ansible/tmp/ansible-tmp-1648530223.610464-14686-129290614671302/ > /dev/null 2>&1 && sleep 0'"'"''
<10.0.0.15> (0, b'', b'')
10.0.0.15 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python3"
},
"changed": false,
"invocation": {
"module_args": {
"data": "pong"
}
},
"ping": "pong"
}
META: ran handlers
META: ran handlers
描述:
1) 加载ansible配置文件、相关模块路径、环境依赖文件
2)使用ansible.cfg配置文件、解析主机清单中的主机
3)为用户建立SSH连接:无;执行exec ssh
4)第二次,为用户建立SSH连接:无;执行exec ssh , 创建并授权 /root/.ansible/tmp 、 /root/.ansible 、/tmp187959444615955
5) 正在尝试python解释器发现
6)为用户建立SSH连接:无;执行exec ssh 查找PLATFORM的python启动
7)为用户建立SSH连接:无;执行exec ssh,这是已加载了python的(platform_dist_result)启动程序,开始调用python执行ansible/modules/ping.py命令
8) 推送 临时的ping.py文件,通过publickey验证,在被远程的主机上执行ping命令并添加执行权限,被远程的主机上显示了ping的执行结果后,被ansible调动模块变量{"module_args": {"data": "pong"}}回传本机;
9)最后,ansible利用 EXEC ssh执行 rm -f -r /root/.ansible/tmp/ansible-tmp* 删除被远程主机的临时生成的命令结果文件。