我正在调用 ansible 剧本,如下所示:
ansible-playbook -vvvv -i inventories/single-brc $TAGS_K8S install-v3-complete.yml --limit 'linux,!localhost,!brc-adv' -e ansible_host=$K8S_HOST $EXTRA ${@:1} -e manifestFileName=$MANIFEST_FILE_NAME -e cellNumber=$CELL_NUMBER
我的库存是:
[plc]
brc-plc ansible_host=0.0.0.0
[linux]
brc-lin ansible_host=0.0.0.0
[advantech]
brc-adv ansible_host=0.0.0.0
但我将我的主机限制为 linux 主机。当我运行 Runbook 时,它会运行我期望的任务,但它也会打印出此意外消息:
brc-adv | UNREACHABLE! => {
"changed": false,
"msg": "basic: HTTPSConnectionPool(host='null', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f4995605850>: Failed to establish a new connection: [Errno -2] Name or service not known'))",
"unreachable": true
}
运行的日志中没有关联的任务。 我特意说过不要针对该主机。为什么 ansible 尝试连接它?我该如何阻止它这样做?
当我像这样使用
--list-hosts
调用我的剧本时:
ansible-playbook -vvvv -i inventories/single-brc $TAGS_K8S install-v3-complete.yml --limit 'linux,!localhost,!brc-adv' -e ansible_host=$K8S_HOST $EXTRA ${@:1} -e manifestFileName=$MANIFEST_FILE_NAME -e cellNumber=$CELL_NUMBER --list-hosts
我们看到 brc-adv 主机不在所选主机列表中:
+ ansible-playbook -vvvv -i inventories/single-brc install-v3-complete.yml --limit 'linux,!localhost,!brc-adv' -e ansible_host=10.125.96.18 -e VIS_HOST=none -e USING_MOCKS=false -e restoreRcpClb=false -e restoreK8sCfg=false -e changeHostname=no -e aws_acct_id=257135567458 -e manifestFileName=manifest.json -e cellNumber=0 --list-hosts
ansible-playbook 2.9.6
config file = /v3-install/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
executable location = /usr/bin/ansible-playbook
python version = 3.8.10 (default, Mar 25 2024, 10:42:49) [GCC 9.4.0]
Using /v3-install/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /v3-install/ansible/inventories/single-brc/hosts as it did not pass its verify_file() method
script declined parsing /v3-install/ansible/inventories/single-brc/hosts as it did not pass its verify_file() method
auto declined parsing /v3-install/ansible/inventories/single-brc/hosts as it did not pass its verify_file() method
Parsed /v3-install/ansible/inventories/single-brc/hosts inventory source with ini plugin
20 plays in install-v3-complete.yml
playbook: install-v3-complete.yml
play #1 (linux): Preparing system TAGS: []
pattern: ['linux']
hosts (1):
brc-lin
play #2 (localhost,all): Setting version TAGS: []
pattern: ['localhost', 'all']
hosts (1):
brc-lin
play #3 (localhost,all): Global variable preparations TAGS: []
pattern: ['localhost', 'all']
hosts (1):
brc-lin
play #4 (localhost,all): AWS preparation TAGS: []
pattern: ['localhost', 'all']
hosts (1):
brc-lin
play #5 (localhost,all): AWS preparation (PLC+IPC) TAGS: []
pattern: ['localhost', 'all']
hosts (1):
brc-lin
play #6 (plc): Validate TwinCAT hosts TAGS: []
pattern: ['plc']
hosts (0):
play #7 (plc): Validate Windows hosts (common) TAGS: []
pattern: ['plc']
hosts (0):
play #8 (linux,localhost): Validate Linux VMs or local TAGS: []
pattern: ['linux', 'localhost']
hosts (1):
brc-lin
play #9 (linux): Validate Linux VMs TAGS: []
pattern: ['linux']
hosts (1):
brc-lin
play #10 (linux): Configure NTP server (linux) TAGS: []
pattern: ['linux']
hosts (1):
brc-lin
play #11 (plc): Configure Windows NTP client (PLC/VIS) TAGS: []
pattern: ['plc']
hosts (0):
play #12 (linux): Importing Image TAGS: []
pattern: ['linux']
hosts (1):
brc-lin
play #13 (localhost,all): Starting install TAGS: []
pattern: ['localhost', 'all']
hosts (1):
brc-lin
play #14 (linux): Set hostname TAGS: []
pattern: ['linux']
hosts (1):
brc-lin
play #15 (linux,localhost): Export RT drivers from the manifest to the mock data files. TAGS: []
pattern: ['linux', 'localhost']
hosts (1):
brc-lin
play #16 (advantech): BRC V3 Linux VM on Advantech TAGS: []
pattern: ['advantech']
hosts (0):
play #17 (linux,localhost): Install BRC V3 software on Advantech Linux VM TAGS: []
pattern: ['linux', 'localhost']
hosts (1):
brc-lin
play #18 (linux,localhost): Install BRC V3 software on Advantech Linux VM (FAKE PLC) TAGS: []
pattern: ['linux', 'localhost']
hosts (1):
brc-lin
play #19 (localhost,linux): load assets into respective services TAGS: [always]
pattern: ['localhost', 'linux']
hosts (1):
brc-lin
play #20 (localhost,linux): localhost,linux TAGS: []
pattern: ['localhost', 'linux']
hosts (1):
brc-lin
+ EXIT_K8S=0
+ set +x
Monday 07 October 2024 19:38:19 +0000 (0:00:00.058) 0:00:00.058 ********
brc-adv | UNREACHABLE! => {
"changed": false,
"msg": "basic: HTTPSConnectionPool(host='null', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7f800e283850>: Failed to establish a new connection: [Errno -2] Name or service not known'))",
"unreachable": true
}
发生这种情况是因为在调用上述 ansible 调用的 shell 脚本中调用了这一行:
ansible brc-adv -i inventories/single-brc-m win_copy -a "dest=$MM_FILE_PATH content='MACHINE_MODE=$MACHINE_MODE'" -e ansible_host=$MMFILE_HOST 2> /dev/null
并且由于 brc-adv 主机无法访问,因此引发错误。
所以 Ansible 正确地没有尝试在我的问题的调用中连接到 brc-adv。随后,它尝试在第二次 Ansible 调用中连接到 brc-adv 主机。