【发布时间】:2017-06-08 16:14:27
【问题描述】:
我的剧本中有三个任务。对于所有这些,Ansible 需要连接到清单文件中指定的主机。前两个任务执行得很好。第三个任务说
<10.182.1.23> ESTABLISH SSH CONNECTION FOR USER: root
<10.182.1.23> SSH: EXEC sshpass -d12 ssh -C -q -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=root -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/ansible-ssh-%h-%p-%r 10.182.1.23 '/bin/sh -c '"'"'( umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1485219301.67-103341754305609 `" && echo ansible-tmp-1485219301.67-103341754305609="` echo $HOME/.ansible/tmp/ansible-tmp-1485219301.67-103341754305609 `" ) && sleep 0'"'"''
fatal: [10.182.1.23]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
这是我的剧本 This is a screenshot of my playbook
这里是 playbook.yml
---
- hosts: all
strategy: debug
gather_facts: no
vars:
contents: "{{ lookup('file','/etc/redhat-release')}}"
mydate: "{{lookup('pipe','date +%Y%m%d%H%M%S**.%5N**')}}"
tasks:
- name: cat file content
debug: msg='the content of file is {{contents}} at date {{mydate}}.'
- name: second task
debug: msg='this is second task at time {{mydate}}.'
- name: fourth task
command: sudo cat /etc/redhat-release
register: result
- debug: var=result
这是我的库存文件
[hosts]
10.182.1.23 ansible_connection=ssh ansible_ssh_user=username ansible_ssh_pass=passphrase
我无法理解它是如何连接到主机以执行前两个任务的,以及为什么它会为第三个任务抛出错误。 我是使用 Ansible 的新手。请帮我解决这个问题。
【问题讨论】: