我正在运行Ansible AWX 1.0.7.2服务器,并在Ubuntu 18.04.1 LTS上使用Ansible 2.6.2。
我正在尝试创建一个Ansible剧本(用于AWX),该剧本可以执行以下操作:
我的工作簿适用于大多数主机。但是,在我的两个实例上,正在创建AMI,但是之后主机显示为无法访问,并且之后的播放失败。
这是我正在使用的剧本:
---
- hosts: all
remote_user: "{{ remote_user }}"
tasks:
- name: Create an AMI for backup
ec2_ami:
instance_id: "{{ instance_id }}"
name: "{{ inventory_hostname }}-{{ ansible_date_time.iso8601_basic_short }}"
tags:
Name: "{{ inventory_hostname }}-{{ ansible_date_time.iso8601_basic_short }}"
register: result
- name: Pause for 120 seconds to allow instance to become reachable again
pause: seconds=120
- include_tasks: update-RedHat.yml
when: (ansible_os_family == 'RedHat' and result.changed|default(false)|bool == true)
- include_tasks: update-Debian.yml
when: (ansible_os_family == 'Debian' and result.changed == true)
剧本失败的输出:
fatal: [testserver.mydomain.com]: UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: OpenSSH_7.6p1 Ubuntu-4, OpenSSL 1.0.2n 7 Dec 2017\r\ndebug1: Reading configuration data /etc/ssh/ssh_config\r\ndebug1: /etc/ssh/ssh_config line 19: Applying options for *\r\ndebug1: auto-mux: Trying existing master\r\ndebug2: fd 3 setting O_NONBLOCK\r\ndebug2: mux_client_hello_exchange: master version 4\r\ndebug3: mux_client_forwards: request forwardings: 0 local, 0 remote\r\ndebug3: mux_client_request_session: entering\r\ndebug3: mux_client_request_alive: entering\r\ndebug3: mux_client_request_alive: done pid = 3353\r\ndebug3: mux_client_request_session: session request sent\r\ndebug1: mux_client_request_session: master session id: 2\r\ndebug3: mux_client_read_packet: read header failed: Broken pipe\r\ndebug2: Control master terminated unexpectedly\r\nShared connection to testserver.mydomain.com closed.\r\n",
"unreachable": true
}
如果失败的实例都连接了较大的(256GB)卷,并且在创建映像时可以使用30-60秒,我想这就是问题所在。但是,插入延迟的多种方法似乎无济于事-不管我做什么,似乎都应该立即检查连通性。
创建图像后,您可以看到暂停。在其他主机上也可以使用此功能,但是在失败的主机上,此功能无法解决,因为在达到该目的之前它已经显示为无法访问。
在图像创建步骤之后,我尝试了此操作:
- name: wait for host to come back up
wait_for: host={{ inventory_hostname }} port=22 delay=60 timeout=180 state=started
但是有相同的失败和消息。
似乎错误在ec2_ami
任务内,所以我也尝试插入wait
:
---
- hosts: all
remote_user: "{{ remote_user }}"
wait: yes
tasks:
- name: Create an AMI for backup
ec2_ami:
instance_id: "{{ instance_id }}"
name: "{{ inventory_hostname }}-{{ ansible_date_time.iso8601_basic_short }}"
tags:
Name: "{{ inventory_hostname }}-{{ ansible_date_time.iso8601_basic_short }}"
register: result
但这没什么区别,实例仍显示为不可访问。
有什么办法可以解决这个问题?