Created
November 21, 2020 22:23
-
-
Save SJrX/079836233cf982e543fa17a588fadc41 to your computer and use it in GitHub Desktop.
Workaround for https://github.com/ansible/ansible/issues/61688
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The following is a workaround for https://github.com/ansible/ansible/issues/61688 | |
# It users the add_host module to change the host (https://docs.ansible.com/ansible/latest/collections/ansible/builtin/add_host_module.html) | |
- name: "Determine IP Address" | |
hosts: localhost | |
tasks: | |
- name: "Check if myhost is at location A" | |
wait_for: | |
host: 192.168.0.100 | |
port: 22 | |
timeout: 1 | |
register: myhost_vpn | |
ignore_errors: yes | |
tags: | |
- always | |
- name: "Add host for myhost at location A" | |
add_host: | |
name: "myhost" | |
hostname: "myhost" | |
ansible_ssh_host: "192.168.0.100" | |
ansible_ssh_user: user | |
ansible_become: yes | |
ansible_become_user: root | |
ansible_become_method: sudo | |
when: myhost_vpn is succeeded | |
tags: | |
- always | |
- name: "Add host for myhost at location B" | |
add_host: | |
name: "myhost" | |
hostname: "myhost" | |
ansible_ssh_host: "10.20.30.40" | |
ansible_ssh_port: 22 | |
ansible_ssh_user: user | |
ansible_become: yes | |
ansible_become_user: root | |
ansible_become_method: sudo | |
when: myhost_vpn is failed | |
tags: | |
- always | |
- name: Setup System | |
hosts: "myhost" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a workaround for: ansible/ansible#61688