I am using the role gcp_connectivity_role to establish the gcp connectivity. And then in the project I am running commands in the project starting from Run shell commands on connected GCP hosts . As expected the connection closes after the role finished its job and then the commands does not run on the hosts i am intended to do. Can you please check if I am following the correct process here ? Please help.
@iamroddo I see you have been working on GCP and AWX. Could you please share your thoughts here if possible ? In simple words,
Do you have a working example of connecting from AWX to GCP hosts (Internal IP only) and running some commands on it?
I setup a constrained example consisting of 2 VMs hosted in GCE and a Linux PC acting as the control node. The VMs are setup using metadata based authentication with an SSH key setup at the project level and are internal-only. The VMs have outbound connectivity via a NAT router. The control node will use the feature of the GCloud CLI to establish a tunnel through the IAP service to connect to the VMs on port 22 which is allowed by the default firewall rules. This same setup should work for Windows VMs using WinRM by forwarding the port for WinRM instead of 22 through the IAP service and allowing it to the VM from IAP’s well known IP range as the source.
ansible-navigator run playbook.yml --inventory hosts
Results in:
$ ansible-navigator run playbook.yml --inventory hosts
PLAY [Activate the `gcloud` CLI] *************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [Activate the `gcloud` CLI] *************************************************************************************************************************************************************************************************************
ok: [localhost]
PLAY [Take action on GCP based managed nodes] ************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ***********************************************************************************************************************************************************************************************************************
[WARNING]: Platform linux on host managed-node-1 is using the discovered Python interpreter at /usr/bin/python3.11, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-core/2.18/reference_appendices/interpreter_discovery.html for more information.
ok: [managed-node-1]
[WARNING]: Platform linux on host managed-node-2 is using the discovered Python interpreter at /usr/bin/python3.11, but future installation of another Python interpreter could change the meaning of that path. See
https://docs.ansible.com/ansible-core/2.18/reference_appendices/interpreter_discovery.html for more information.
ok: [managed-node-2]
TASK [Print hostname] ************************************************************************************************************************************************************************************************************************
ok: [managed-node-1] => {
"ansible_hostname": "managed-node-1"
}
ok: [managed-node-2] => {
"ansible_hostname": "managed-node-2"
}
PLAY RECAP ***********************************************************************************************************************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
managed-node-1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
managed-node-2 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
@wayt , Thanks again. While you are still here, I want some help on adding a custom variable as hostvars in the inventory. But none of the below values are getting populated in the hostvars for my hosts. Am I doing anything wrong ? Please help .