gpt4 book ai didi

Ansible 等待 ssh 不起作用

转载 作者:行者123 更新时间:2023-12-02 00:59:29 28 4
gpt4 key购买 nike

Ansible wait_for ssh 停止工作。 Ansible playbook 能够启动 ec2 实例,wait_for模块正在用于等待 ssh 启动。 Ansible 在等待 ssh 时超时。

我的剧本

- name: Configuring and lanuching EC2 instance
hosts: localhost
connection: local
vars_files:
- general_vars

tasks:
- name: Launch instance
ec2:
instance_type: "{{ instance_type }}"
image: "{{ image_ami }}"
region: "{{ region }}"
vpc_subnet_id: "{{ subnet_id }}"
assign_public_ip: yes
group_id: "{{ security_group }}"
key_name: "{{ key_pair }}"
volumes:
- device_name: /dev/xvda
volume_type: gp2
volume_size: 8

register: ec2

- name: Wait for ssh to come up
wait_for: host="{{ ec2.instances[0].public_dns_name }}" port=22 delay=10 timeout=300
with_items: "{{ ec2.instances }}"
- name: Save the Ip Address of the machine
add_host:
hostname: "{{ item.public_ip }}"
groupname: ec2_instance_ips
with_items: "{{ ec2.instances }}"

错误跟踪
The full traceback is:
File "/var/folders/y3/t87nx4q95w9_jmg80csrn6bc0000gn/T/ansible_SpGSRH/ansible_module_wait_for.py", line 540, in main
s = _create_connection(host, port, min(connect_timeout, alt_connect_timeout))
File "/var/folders/y3/t87nx4q95w9_jmg80csrn6bc0000gn/T/ansible_SpGSRH/ansible_module_wait_for.py", line 405, in _create_connection
connect_socket = socket.create_connection((host, port), connect_timeout)
File "/usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err

}) => {
"changed": false,
"elapsed": 300,
"invocation": {
"module_args": {
"active_connection_states": [
"ESTABLISHED",
"FIN_WAIT1",
"FIN_WAIT2",
"SYN_RECV",
"SYN_SENT",
"TIME_WAIT"
],
"connect_timeout": 5,
"delay": 10,
"exclude_hosts": null,
"host": "",
"msg": null,
"path": null,
"port": 22,
"search_regex": null,
"sleep": 1,
"state": "started",
"timeout": 300
}
},
"item": {
"ami_launch_index": "0",
"architecture": "x86_64",
"block_device_mapping": {},
"dns_name": "",
"ebs_optimized": false,
"groups": {
"sg-09664e62": "yyyzzzzbbbbbb"
},
"hypervisor": "xen",
"id": "i-XXxxxxxxxxxxxxxxx",
"image_id": "XXXXXXXXXXXXX",
"instance_type": "t2.micro",
"kernel": null,
"key_name": "XXXX",
"launch_time": "XXXXXX",
"placement": "ccccccccccccccc",
"private_dns_name": "",
"private_ip": "XXXXX",
"public_dns_name": "",
"public_ip": null,
"ramdisk": null,
"region": "XXXX",
"root_device_name": "/dev/sda1",
"root_device_type": "ebs",
"state": "pending",
"state_code": 0,
"tags": {},
"tenancy": "default",
"virtualization_type": "hvm"
},
"msg": "Timeout when waiting for :22"

Ansible 没有为 public_dns_name 返回任何内容和 public_ip一片空白”。

因此, wait_for ssh 失败,即使 ec2 已正确生成并且我能够手动通过适当的 key ssh 到机器。

我做错了什么?

最佳答案

- name: Wait for ssh to come up
wait_for: host="{{ ec2.instances[0].public_dns_name }}" port=22 delay=10 timeout=300
with_items: "{{ ec2.instances }}"


您正在使用 with_items构造,但我看不到 item 的任何用途多变的。我不使用 AWS,但也许你需要
 - name: Wait for ssh to come up
wait_for: host="{{ item.public_dns_name }}" port=22 delay=10 timeout=300
with_items: "{{ ec2.instances }}"

关于Ansible 等待 ssh 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51592144/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com