--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ae22b634-63ea-4335-8577-1f75c8f5aaa4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You can run a ping task with ignore errors and register result, then conditionally create the user with diff remote user based on that.
Brian Coca
PLAY [playbook] *****************************************************************
TASK: [Check if we can connect using ping module.] ****************************
fatal: [drupal] => SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue
---
- name: Check if we can connect using the normal user.
command: "ssh -oBatchMode=yes {{ admin_user }}@{{ ansible_ssh_host }} exit"
failed_when: false
changed_when: false
register: ssh_result
connection: local
sudo: no
- debug: var=user_creation_account
- name: Switch user account if necessary.
set_fact: user_creation_account="root"
when: ssh_result.rc != 0
connection: local
sudo: no
- debug: var=user_creation_account
--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/da689eb9-4a16-43bd-b60f-966ebde281b7%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/a3b074d0-5f6d-4b57-b841-fc9d13109146%40googlegroups.com.
Do you actually need to detect at all?
- name: Attempt SSH as initialUser - succeeds only if user customization not yet done (also adds private IP(s) to known_hosts, when succeeds)
shell: "ssh -o StrictHostKeyChecking=no -i ../ssh/{{ key_name }} {{ initialUser }}@{{ item.private_ip }} 'exit'"
with_items: ec2.tagged_instances
when: wait == "yes"
ignore_errors: yes
register: ssh_attempt
- name: Add instance(s) still requiring user customization to 'host_users_customized_False' group
local_action: add_host hostname={{ item.item.private_ip }} groupname="host_users_customized_False"
with_items: ssh_attempt.results
when: wait == "yes" and item.rc == 0
- name: Re-SSH as initialUser using private DNS name(s) instead of IP(s), to also add them to known_hosts (skips if first attempt failed)
shell: "ssh -o StrictHostKeyChecking=no -i ../ssh/{{ key_name }} {{ initialUser }}@{{ item.item.private_dns_name }} 'exit'"
with_items: ssh_attempt.results
when: wait == "yes" and item.rc == 0
ignore_errors: yes