在我的主机中,需要时间(大约20秒)来初始化CLI会话,...在执行cli之前
我试图通过剧本ansible来做命令:
---
- name: Run show sub command
hosts: em
gather_facts: no
remote_user: duypn
tasks:
- name: wait for SSH to respond on all hosts
local_action: wait_for host=em port=22 delay=60 state=started
- name: run show sub command
raw: show sub id=xxxxx;display=term-type
10分钟后,ansible给出了输出,这不是show sub命令的结果:(
...
["CLI Session initializing..", "Autocompleter initializing..", "CLI>This session has been IDLE for too long.",
...
我很高兴听到你的建议。谢谢:))
答案 0 :(得分:1)
我没有适合你的复制粘贴解决方案,但我学到的一件事就是在ssh'up'之后暂停睡眠以让机器完成它的工作。这可能会让你在正确的方向上轻推。
- name: Wait for SSH to come up
local_action: wait_for
host={{ item.public_ip }}
port=22
state=started
with_items: "{{ ec2.instances }}"
- name: waiting for a few seconds to let the machine start
pause:
seconds: 20
答案 1 :(得分:0)
所以我遇到了同样的问题,这就是我解决它的方法:
---
- name: "Get instances info"
ec2_instance_facts:
aws_access_key: "{{ aws_access_key }}"
aws_secret_key: "{{ aws_secret_key }}"
region: "{{ aws_region }}"
filters:
vpc-id : "{{ vpc_id }}"
private-ip-address: "{{ ansible_ssh_host }}"
delegate_to: localhost
register: my_ec2
- name: "Waiting for {{ hostname }} to response"
wait_for:
host: "{{ item.public_ip_address }}"
state: "{{ state }}"
sleep: 1
port: 22
delegate_to: localhost
with_items:
- "{{ my_ec2.instances }}"
这就是名为aws_ec2_status
的剧本。
我跑的剧本看起来像这样:
---
# Create an ec2 instance in aws
- hosts: nodes
gather_facts: false
serial: 1
vars:
state: "present"
roles:
- aws_create_ec2
- hosts: nodes
gather_facts: no
vars:
state: "started"
roles:
- aws_ec2_status
我将创建和检查拆分为两个不同的剧本的原因是因为我希望剧本创建实例而不是在创建另一个之前等待其准备好。 但是如果第二个实例依赖于第一个实例,那么你应该将它们组合起来。
仅供参考。如果您想查看我的aws_create_ec2
剧本,请告诉我。