I ran into a (for me) unexpected issue with ansible
when trying to execute the following:
# myplaybook.ansible.yml
- hosts: myhost2
tasks:
- name: Execute pgsql query
community.postgresql.postgresql_query:
...
where myhost1
is the controller executing ansible-playbook -v myplaybook.ansible.yml
.
On the target host myhost2
community.postgresql.postgresql_query
is installed with ansible-galaxy install
and the dependencies (notably psycopg2
) satisfied.
The problem:
ansible
bombs out before actually evaluating the playbook because it can't find the postgresql_query
module on the controller, but the whole purpose of running this on myhost2
is to avoid having to install such dependencies on the controller in the first place.
Similarly, I'd also like to be able to execute the above like this, which obviously doesn't work for the same reason:
# myplaybook.ansible.yml
- hosts: myhost3
tasks:
- name: Execute pgsql query
delegate_to: myhost2
community.postgresql.postgresql_query:
...
The Question
How to only evaluate an ansible
module called in a task on the target or delegate host?