目前尝试在Centos7上的Ansible安装上运行一个简单的手册,一切都是最新的。我可以运行一个简单的原始模块并指定主机,但是当我运行playbook时,我得到一个"无法解析主机名"
以下是日志
[root@ohnetwork01 playbooks]# ansible-playbook -vvvvvv -u user.user -k version_playbook.yaml
Using /etc/ansible/ansible.cfg as config file
SSH password:
Loaded callback default of type stdout, v2.0
PLAYBOOK: version_playbook.yaml ************************************************
1 plays in version_playbook.yaml
PLAY [Get version] *************************************************************
TASK [setup] *******************************************************************
<192.168.1.34> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.34> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529280.8-264756931089857 `" && echo ansible-tmp-1466529280.8-264756931089857="` echo /tmp/ansible/ansible-tmp-1466529280.8-264756931089857 `" ) && sleep 0'
<192.168.1.33> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.33> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529280.8-152708795243660 `" && echo ansible-tmp-1466529280.8-152708795243660="` echo /tmp/ansible/ansible-tmp-1466529280.8-152708795243660 `" ) && sleep 0'
<192.168.1.34> PUT /tmp/tmpymgKXv TO /tmp/ansible/ansible-tmp-1466529280.8-264756931089857/setup
<192.168.1.34> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529280.8-264756931089857/setup; rm -rf "/tmp/ansible/ansible-tmp-1466529280.8-264756931089857/" > /dev/null 2>&1 && sleep 0'
<192.168.1.33> PUT /tmp/tmpW5FEgv TO /tmp/ansible/ansible-tmp-1466529280.8-152708795243660/setup
<192.168.1.33> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529280.8-152708795243660/setup; rm -rf "/tmp/ansible/ansible-tmp-1466529280.8-152708795243660/" > /dev/null 2>&1 && sleep 0'
ok: [P-9396PXb.domain.local]
ok: [P-9396PXa.domain.local]
TASK [nxos_facts] **************************************************************
task path: /home/user/playbooks/version_playbook.yaml:8
<192.168.1.33> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.33> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529281.26-258697976681834 `" && echo ansible-tmp-1466529281.26-258697976681834="` echo /tmp/ansible/ansible-tmp-1466529281.26-258697976681834 `" ) && sleep 0'
<192.168.1.34> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.1.34> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /tmp/ansible/ansible-tmp-1466529281.26-135897636845763 `" && echo ansible-tmp-1466529281.26-135897636845763="` echo /tmp/ansible/ansible-tmp-1466529281.26-135897636845763 `" ) && sleep 0'
<192.168.1.33> PUT /tmp/tmpvaaDMQ TO /tmp/ansible/ansible-tmp-1466529281.26-258697976681834/nxos_facts
<192.168.1.33> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529281.26-258697976681834/nxos_facts; rm -rf "/tmp/ansible/ansible-tmp-1466529281.26-258697976681834/" > /dev/null 2>&1 && sleep 0'
<192.168.1.34> PUT /tmp/tmpK7TYAS TO /tmp/ansible/ansible-tmp-1466529281.26-135897636845763/nxos_facts
<192.168.1.34> EXEC /bin/sh -c 'LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /tmp/ansible/ansible-tmp-1466529281.26-135897636845763/nxos_facts; rm -rf "/tmp/ansible/ansible-tmp-1466529281.26-135897636845763/" > /dev/null 2>&1 && sleep 0'
fatal: [P-9396PXa.domain.local]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"host": "", "password": null, "port": null, "provider": null, "ssh_keyfile": null, "transport": "cli", "use_ssl": false, "username": null, "validate_certs": true}, "module_name": "nxos_facts"}, "msg": "failed to connect to :22 - unable to resolve host name"}
fatal: [P-9396PXb.domain.local]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_args": {"host": "", "password": null, "port": null, "provider": null, "ssh_keyfile": null, "transport": "cli", "use_ssl": false, "username": null, "validate_certs": true}, "module_name": "nxos_facts"}, "msg": "failed to connect to :22 - unable to resolve host name"}
NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @version_playbook.retry
PLAY RECAP *********************************************************************
P-9396PXa.domain.local : ok=1 changed=0 unreachable=0 failed=1
P-9396PXb.domain.local : ok=1 changed=0 unreachable=0 failed=1
这是我使用的主机文件和剧本,非常简单,因为我只是想测试
#### Host entry ####
[ProdCoreSwitches]
P-9396PXa.domain.local ansible_host=192.168.1.33
P-9396PXb.domain.local ansible_host=192.168.1.34
#### Playbook ####
---
- name: Get version
connection: local
hosts: ProdCoreSwitches
tasks:
- nxos_facts:
host= "{{ inventory_hostname }}"
我应该改变什么?
编辑:从本地更改连接后,我得到以下内容:
fatal: [P-9396PXa.domain.local]: UNREACHABLE! => {"changed": false, "msg": "Authentication or permission failure. In some cases, you may have been able to authenticate and did not have permissions on the remote directory. Consider changing the remote temp path in ansible.cfg to a path rooted in \"/tmp\". Failed command was: ( umask 77 && mkdir -p \"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" && echo ansible-tmp-1466538148.97-100745005340782=\"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" ), exited with result 16: Syntax error while parsing '/bin/sh -c '( umask 77 && mkdir -p \"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" && echo ansible-tmp-1466538148.97-100745005340782=\"` echo /tmp/ansible/ansible-tmp-1466538148.97-100745005340782 `\" ) && sleep 0''\n\n\nCmd exec error.\n", "unreachable": true}
答案 0 :(得分:0)
您能否显示任务“nxos_facts”的内容?您在哪里定义了“{{inventory_hostname}}”以及值是什么?