Unable to running shell command on target host

,

Hi All,

I notice that when using AAP/AWX with execution-envrionment, I was no longer able run command on the target machine. It seems like ansible.builtin.shell will actually perform the command within the execution environment. What is the official way of running command on the target machine with execution envrionment ?

Regards,

David Tio

1 Like

@dtio hi, yes, that’s correct as the control node -and playbooks respectively- now run inside the container, so now you need to treat your actual localhost as a remote target if you want to run tasks against it. Any other thoughts from experts?

BTW there’s a set of Quick start docs introduced last autumn, may be helpful.

Hello @dtio welcome to Ansible Community Forum!

If I understood your inquiry correctly, what you want to do is to execute shell commands on a remote target (managed host), right?

If that’s so, it doesn’t matter if you’re using an EE on AWX (you can do the same with ansible-navigator in fact). The way to go is to create an inventory on your AWX / AAP instance with the target hosts on it, and then select this very same inventory on the Job Template that runs your playbook. You can also limit the execution to specific groups or hosts within the inventory using the limit option on the JT.

If you still have doubts about this, I can provide you with a simplified example.

Cheers!

PS: Also, consider using the ansible.builtin.command module instead of the ansible.builtin.shell, as noted in the module documentation:

If you want to execute a command securely and predictably, it may be better to use the ansible.builtin.command module instead. Best practices when writing playbooks will follow the trend of using ansible.builtin.command unless the ansible.builtin.shell module is explicitly required. When running ad-hoc commands, use your best judgement