ansible-playbook wait for ssh timing out with ping error, but works locally
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am trying to ssh to an ec2 instance, via my ansible-playbook file. I can ssh into the instance locally, and currently have the following configuration in my ansible-playbook file:
- name: Wait for SSH to come up
delegate_to: "{{ public_dns }}"
wait_for_connection:
delay: 60
timeout: 120
with_items: "{{ public_ip }}"
remote_user: ubuntu
connection: ssh
register: item
However, when I run this, I get the following error:
failed: [localhost -> {{ public_dns }}] (item={'_ansible_item_result':
True, '_ansible_no_log': False, '_ansible_delegated_vars':
{'ansible_delegated_host': u'{{ public_dns }}', 'ansible_host': u'{{
public_dns }}'}, 'changed': False, 'elapsed': 184, 'failed': True,
'item': u'{{ public_ip }}', 'msg': u"timed out waiting for ping module
test success: 'ping'", '_ansible_ignore_errors': None}) => {"changed":
false, "elapsed": 184, "item": "{{ public_ip }}", "msg": "timed out
waiting for ping module test success: 'ping'"}
When I ping the public_dns or public_ip value from my machine both are successful.
Why would the ping event fail when running the Ansible file? (I'm not purposefully trying to ping the instance, I actually want to connect to it via ssh. However the error shows that Ansible may be trying to ping the instance before connecting, based on the "timed out waiting for ping module test success")
I have since changed the method to:
- name: Add new instance to host group
add_host:
hostname: ""{{ public_ip }}"
groupname: launched
- name: Wait for SSH to come up
wait_for:
host: launched
port: 22
sleep: 30
delay: 10
timeout: 360
state: started
However, this has been throwing a different error, of "Timeout when waiting for launched:22" The traceback includes the following:
connect_socket = socket.create_connection((host, port), connect_timeout) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):.
Any ideas?
amazon-ec2 ansible
add a comment |
I am trying to ssh to an ec2 instance, via my ansible-playbook file. I can ssh into the instance locally, and currently have the following configuration in my ansible-playbook file:
- name: Wait for SSH to come up
delegate_to: "{{ public_dns }}"
wait_for_connection:
delay: 60
timeout: 120
with_items: "{{ public_ip }}"
remote_user: ubuntu
connection: ssh
register: item
However, when I run this, I get the following error:
failed: [localhost -> {{ public_dns }}] (item={'_ansible_item_result':
True, '_ansible_no_log': False, '_ansible_delegated_vars':
{'ansible_delegated_host': u'{{ public_dns }}', 'ansible_host': u'{{
public_dns }}'}, 'changed': False, 'elapsed': 184, 'failed': True,
'item': u'{{ public_ip }}', 'msg': u"timed out waiting for ping module
test success: 'ping'", '_ansible_ignore_errors': None}) => {"changed":
false, "elapsed": 184, "item": "{{ public_ip }}", "msg": "timed out
waiting for ping module test success: 'ping'"}
When I ping the public_dns or public_ip value from my machine both are successful.
Why would the ping event fail when running the Ansible file? (I'm not purposefully trying to ping the instance, I actually want to connect to it via ssh. However the error shows that Ansible may be trying to ping the instance before connecting, based on the "timed out waiting for ping module test success")
I have since changed the method to:
- name: Add new instance to host group
add_host:
hostname: ""{{ public_ip }}"
groupname: launched
- name: Wait for SSH to come up
wait_for:
host: launched
port: 22
sleep: 30
delay: 10
timeout: 360
state: started
However, this has been throwing a different error, of "Timeout when waiting for launched:22" The traceback includes the following:
connect_socket = socket.create_connection((host, port), connect_timeout) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):.
Any ideas?
amazon-ec2 ansible
there is two"inhostname: ""{{ public_ip }}"but I think it's just a wrong copy paste in stackoverflow
– bast
Nov 28 '18 at 12:15
add a comment |
I am trying to ssh to an ec2 instance, via my ansible-playbook file. I can ssh into the instance locally, and currently have the following configuration in my ansible-playbook file:
- name: Wait for SSH to come up
delegate_to: "{{ public_dns }}"
wait_for_connection:
delay: 60
timeout: 120
with_items: "{{ public_ip }}"
remote_user: ubuntu
connection: ssh
register: item
However, when I run this, I get the following error:
failed: [localhost -> {{ public_dns }}] (item={'_ansible_item_result':
True, '_ansible_no_log': False, '_ansible_delegated_vars':
{'ansible_delegated_host': u'{{ public_dns }}', 'ansible_host': u'{{
public_dns }}'}, 'changed': False, 'elapsed': 184, 'failed': True,
'item': u'{{ public_ip }}', 'msg': u"timed out waiting for ping module
test success: 'ping'", '_ansible_ignore_errors': None}) => {"changed":
false, "elapsed": 184, "item": "{{ public_ip }}", "msg": "timed out
waiting for ping module test success: 'ping'"}
When I ping the public_dns or public_ip value from my machine both are successful.
Why would the ping event fail when running the Ansible file? (I'm not purposefully trying to ping the instance, I actually want to connect to it via ssh. However the error shows that Ansible may be trying to ping the instance before connecting, based on the "timed out waiting for ping module test success")
I have since changed the method to:
- name: Add new instance to host group
add_host:
hostname: ""{{ public_ip }}"
groupname: launched
- name: Wait for SSH to come up
wait_for:
host: launched
port: 22
sleep: 30
delay: 10
timeout: 360
state: started
However, this has been throwing a different error, of "Timeout when waiting for launched:22" The traceback includes the following:
connect_socket = socket.create_connection((host, port), connect_timeout) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):.
Any ideas?
amazon-ec2 ansible
I am trying to ssh to an ec2 instance, via my ansible-playbook file. I can ssh into the instance locally, and currently have the following configuration in my ansible-playbook file:
- name: Wait for SSH to come up
delegate_to: "{{ public_dns }}"
wait_for_connection:
delay: 60
timeout: 120
with_items: "{{ public_ip }}"
remote_user: ubuntu
connection: ssh
register: item
However, when I run this, I get the following error:
failed: [localhost -> {{ public_dns }}] (item={'_ansible_item_result':
True, '_ansible_no_log': False, '_ansible_delegated_vars':
{'ansible_delegated_host': u'{{ public_dns }}', 'ansible_host': u'{{
public_dns }}'}, 'changed': False, 'elapsed': 184, 'failed': True,
'item': u'{{ public_ip }}', 'msg': u"timed out waiting for ping module
test success: 'ping'", '_ansible_ignore_errors': None}) => {"changed":
false, "elapsed": 184, "item": "{{ public_ip }}", "msg": "timed out
waiting for ping module test success: 'ping'"}
When I ping the public_dns or public_ip value from my machine both are successful.
Why would the ping event fail when running the Ansible file? (I'm not purposefully trying to ping the instance, I actually want to connect to it via ssh. However the error shows that Ansible may be trying to ping the instance before connecting, based on the "timed out waiting for ping module test success")
I have since changed the method to:
- name: Add new instance to host group
add_host:
hostname: ""{{ public_ip }}"
groupname: launched
- name: Wait for SSH to come up
wait_for:
host: launched
port: 22
sleep: 30
delay: 10
timeout: 360
state: started
However, this has been throwing a different error, of "Timeout when waiting for launched:22" The traceback includes the following:
connect_socket = socket.create_connection((host, port), connect_timeout) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):.
Any ideas?
amazon-ec2 ansible
amazon-ec2 ansible
edited Nov 22 '18 at 21:15
fuzzi
asked Nov 16 '18 at 18:33
fuzzifuzzi
2481932
2481932
there is two"inhostname: ""{{ public_ip }}"but I think it's just a wrong copy paste in stackoverflow
– bast
Nov 28 '18 at 12:15
add a comment |
there is two"inhostname: ""{{ public_ip }}"but I think it's just a wrong copy paste in stackoverflow
– bast
Nov 28 '18 at 12:15
there is two
" in hostname: ""{{ public_ip }}" but I think it's just a wrong copy paste in stackoverflow– bast
Nov 28 '18 at 12:15
there is two
" in hostname: ""{{ public_ip }}" but I think it's just a wrong copy paste in stackoverflow– bast
Nov 28 '18 at 12:15
add a comment |
1 Answer
1
active
oldest
votes
Please note that Ansible ping module is not the same as ICMP Ping: https://docs.ansible.com/ansible/2.5/modules/ping_module.html. Ansible will try to connect to the target host via ssh when using the ping module
If the above task is inside a playbook that is run against a newly provisioned ec2 instance, I would set gather_facts: false and run the wait_for_connection as my first task. If it still fails, try increasing the timeout parameter
thanks for your answer. I've tried both the gather_facts and moving the wait_for_connection task, however this is still failing, I think that it may not be correctly using the sshkey? - any advice on this?
– fuzzi
Nov 21 '18 at 19:16
I think the error message would say something about authentication if you're using the wrong sshkey. Have you tried increasing thetimeoutparameter?
– Domingo Tamayo
Nov 22 '18 at 10:35
Yes I have increased it to 600 seconds, and this is well after I can ssh into the machine outside of the ansible script.
– fuzzi
Nov 22 '18 at 21:11
Just saw your updated code and I agree that it's cleaner and simpler now. Quick comment: shouldn'thost: launchedpoint to the actual host{{ public_up }}instead of the group?
– Domingo Tamayo
Nov 23 '18 at 0:32
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343536%2fansible-playbook-wait-for-ssh-timing-out-with-ping-error-but-works-locally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please note that Ansible ping module is not the same as ICMP Ping: https://docs.ansible.com/ansible/2.5/modules/ping_module.html. Ansible will try to connect to the target host via ssh when using the ping module
If the above task is inside a playbook that is run against a newly provisioned ec2 instance, I would set gather_facts: false and run the wait_for_connection as my first task. If it still fails, try increasing the timeout parameter
thanks for your answer. I've tried both the gather_facts and moving the wait_for_connection task, however this is still failing, I think that it may not be correctly using the sshkey? - any advice on this?
– fuzzi
Nov 21 '18 at 19:16
I think the error message would say something about authentication if you're using the wrong sshkey. Have you tried increasing thetimeoutparameter?
– Domingo Tamayo
Nov 22 '18 at 10:35
Yes I have increased it to 600 seconds, and this is well after I can ssh into the machine outside of the ansible script.
– fuzzi
Nov 22 '18 at 21:11
Just saw your updated code and I agree that it's cleaner and simpler now. Quick comment: shouldn'thost: launchedpoint to the actual host{{ public_up }}instead of the group?
– Domingo Tamayo
Nov 23 '18 at 0:32
add a comment |
Please note that Ansible ping module is not the same as ICMP Ping: https://docs.ansible.com/ansible/2.5/modules/ping_module.html. Ansible will try to connect to the target host via ssh when using the ping module
If the above task is inside a playbook that is run against a newly provisioned ec2 instance, I would set gather_facts: false and run the wait_for_connection as my first task. If it still fails, try increasing the timeout parameter
thanks for your answer. I've tried both the gather_facts and moving the wait_for_connection task, however this is still failing, I think that it may not be correctly using the sshkey? - any advice on this?
– fuzzi
Nov 21 '18 at 19:16
I think the error message would say something about authentication if you're using the wrong sshkey. Have you tried increasing thetimeoutparameter?
– Domingo Tamayo
Nov 22 '18 at 10:35
Yes I have increased it to 600 seconds, and this is well after I can ssh into the machine outside of the ansible script.
– fuzzi
Nov 22 '18 at 21:11
Just saw your updated code and I agree that it's cleaner and simpler now. Quick comment: shouldn'thost: launchedpoint to the actual host{{ public_up }}instead of the group?
– Domingo Tamayo
Nov 23 '18 at 0:32
add a comment |
Please note that Ansible ping module is not the same as ICMP Ping: https://docs.ansible.com/ansible/2.5/modules/ping_module.html. Ansible will try to connect to the target host via ssh when using the ping module
If the above task is inside a playbook that is run against a newly provisioned ec2 instance, I would set gather_facts: false and run the wait_for_connection as my first task. If it still fails, try increasing the timeout parameter
Please note that Ansible ping module is not the same as ICMP Ping: https://docs.ansible.com/ansible/2.5/modules/ping_module.html. Ansible will try to connect to the target host via ssh when using the ping module
If the above task is inside a playbook that is run against a newly provisioned ec2 instance, I would set gather_facts: false and run the wait_for_connection as my first task. If it still fails, try increasing the timeout parameter
answered Nov 20 '18 at 11:56
Domingo TamayoDomingo Tamayo
13612
13612
thanks for your answer. I've tried both the gather_facts and moving the wait_for_connection task, however this is still failing, I think that it may not be correctly using the sshkey? - any advice on this?
– fuzzi
Nov 21 '18 at 19:16
I think the error message would say something about authentication if you're using the wrong sshkey. Have you tried increasing thetimeoutparameter?
– Domingo Tamayo
Nov 22 '18 at 10:35
Yes I have increased it to 600 seconds, and this is well after I can ssh into the machine outside of the ansible script.
– fuzzi
Nov 22 '18 at 21:11
Just saw your updated code and I agree that it's cleaner and simpler now. Quick comment: shouldn'thost: launchedpoint to the actual host{{ public_up }}instead of the group?
– Domingo Tamayo
Nov 23 '18 at 0:32
add a comment |
thanks for your answer. I've tried both the gather_facts and moving the wait_for_connection task, however this is still failing, I think that it may not be correctly using the sshkey? - any advice on this?
– fuzzi
Nov 21 '18 at 19:16
I think the error message would say something about authentication if you're using the wrong sshkey. Have you tried increasing thetimeoutparameter?
– Domingo Tamayo
Nov 22 '18 at 10:35
Yes I have increased it to 600 seconds, and this is well after I can ssh into the machine outside of the ansible script.
– fuzzi
Nov 22 '18 at 21:11
Just saw your updated code and I agree that it's cleaner and simpler now. Quick comment: shouldn'thost: launchedpoint to the actual host{{ public_up }}instead of the group?
– Domingo Tamayo
Nov 23 '18 at 0:32
thanks for your answer. I've tried both the gather_facts and moving the wait_for_connection task, however this is still failing, I think that it may not be correctly using the sshkey? - any advice on this?
– fuzzi
Nov 21 '18 at 19:16
thanks for your answer. I've tried both the gather_facts and moving the wait_for_connection task, however this is still failing, I think that it may not be correctly using the sshkey? - any advice on this?
– fuzzi
Nov 21 '18 at 19:16
I think the error message would say something about authentication if you're using the wrong sshkey. Have you tried increasing the
timeout parameter?– Domingo Tamayo
Nov 22 '18 at 10:35
I think the error message would say something about authentication if you're using the wrong sshkey. Have you tried increasing the
timeout parameter?– Domingo Tamayo
Nov 22 '18 at 10:35
Yes I have increased it to 600 seconds, and this is well after I can ssh into the machine outside of the ansible script.
– fuzzi
Nov 22 '18 at 21:11
Yes I have increased it to 600 seconds, and this is well after I can ssh into the machine outside of the ansible script.
– fuzzi
Nov 22 '18 at 21:11
Just saw your updated code and I agree that it's cleaner and simpler now. Quick comment: shouldn't
host: launched point to the actual host {{ public_up }} instead of the group?– Domingo Tamayo
Nov 23 '18 at 0:32
Just saw your updated code and I agree that it's cleaner and simpler now. Quick comment: shouldn't
host: launched point to the actual host {{ public_up }} instead of the group?– Domingo Tamayo
Nov 23 '18 at 0:32
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53343536%2fansible-playbook-wait-for-ssh-timing-out-with-ping-error-but-works-locally%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
there is two
"inhostname: ""{{ public_ip }}"but I think it's just a wrong copy paste in stackoverflow– bast
Nov 28 '18 at 12:15