我的playbook有問題,應該通過內置模塊創建新的EC2實例並連接到它們以設置一些默認的東西。在相同腳本中創建槽ec2模塊後無法訪問機器
我去了很多教程/帖子,但沒有人提到相同的問題,因此我在那裏問。
就創建而言,一切都很順利,但是當我創建實例併成功等待SSH出現時。我說錯誤,說機器無法訪問。
UNREACHABLE! => {"changed": false, "msg": "ERROR! SSH Error: data could not be sent to the remote host. Make sure this host can be reached over ssh", "unreachable": true}
我試圖手動連接(從終端到同一主機),我很成功(而劇本等待連接)。我也嘗試在ansible.cfg中增加超時。我證實了給定的主機名是有效的(也是),並且還嘗試了公有的ip而不是公有的DNS,但沒有任何幫助。
基本上我的劇本看起來像
---
- name: create ec2 instances
hosts: local
connection: local
gather_facts: False
vars:
machines:
- { type: "t2.micro", instance_tags: { Name: "machine1", group: "some_group" }, security_group: ["SSH"] }
tasks:
- name: lunch new ec2 instances
local_action: ec2
group={{ item.security_group }}
instance_type={{ item.type}}
image=...
wait=true
region=...
keypair=...
count=1
instance_tags=...
with_items: machines
register: ec2
- name: wait for SSH to come up
local_action: wait_for host={{ item.instances.0.public_dns_name }} port=22 delay=60 timeout=320 state=started
with_items: ec2.results
- name: add host into launched group
add_host: name={{ item.instances.0.public_ip }} group=launched
with_items: ec2.results
- name: with the newly provisioned EC2 node configure basic stuff
hosts: launched
sudo: yes
remote_user: ubuntu
gather_facts: True
roles:
- common
注:在很多教程從創建不同的方式訪問EC2實例的結果,但是那可能是不同的問題。
感謝
解決:
我不知道怎麼回事,但它突然開始工作。沒有線索。在情況下,我會發現一些新的信息,會更新這個問題
你究竟在哪裏得到這個錯誤?哪個玩法? – helloV
它在共同角色(set_hostname)中的第一個任務。基本上,當我第一次嘗試訪問新機器時。分離成兩個劇本(必須分開管理)的作品,但我不喜歡它 –