redhat-cop / ee_utilities

This ansible collection includes a number of roles and tools which can be useful for managing Ansible Execution Environments.
https://galaxy.ansible.com/infra/ee_utilities
GNU General Public License v3.0
57 stars 34 forks source link

delegate_to: localhost prevents running on a remote machine #148

Closed arjanhak closed 7 months ago

arjanhak commented 7 months ago

Summary

I created a playbook that runs the infra.ee_utilities.ee_builder on a remote host, but I cannot use the ee_create_controller_def as part of the block are wrongfully executed on localhost.

Issue Type

Ansible, Collection, Docker/Podman details

$ ansible --version
ansible [core 2.15.9]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/myuser/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/myuser/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.16 (main, Sep 12 2023, 00:00:00) [GCC 11.3.1 20221121 (Red Hat 11.3.1-4)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

$ ansible-galaxy collection list

# /home/myuser/.ansible/collections/ansible_collections
Collection         Version
------------------ -------
containers.podman  1.12.0
infra.ee_utilities 3.1.3

$ podman --version
podman version 4.6.1

OS / ENVIRONMENT

Desired Behavior

When I have a playbook that runs on a remote machine, I want to use the set_stats module to export the execution environment(s) meta information to the infra.controller_configuration.execution_environments role.

Actual Behavior

Task "Create temporary folder" in roles/ee_builder/tasks/main.yml successfully creates the temporary directory on the remote machine, I can see it there. But the next task "Create execution environment definition file" fails because the directory does not exist on localhost. If the "delegate_to: localhost" had not been there (also for the next task below it) then it would have worked afaik.

TASK [infra.ee_utilities.ee_builder : Create temporary folder] *****************
changed: [server.domain.com]
TASK [infra.ee_utilities.ee_builder : Create execution environment definition file] ***
fatal: [server.domain.com -> localhost]: FAILED! => {"changed": false, "checksum": "fe4ede2cc72683c7e3afecc329685a9ab072c0ac", "msg": "Destination directory /tmp/ansible.elb4u1k7temp does not exist"}

STEPS TO REPRODUCE

---
- name: Playbook to create custom Execution Environment(s)
  hosts: server.domain.com
  gather_facts: false
  collections:
    - infra.ee_utilities

  vars:
    ...
    ee_create_controller_def: true
    ee_list:
      ...

  tasks:
    ...

    - name: "Include role infra.ee_utilities.ee_builder"
      include_role:
        name: infra.ee_utilities.ee_builder

    ...
Tompage1994 commented 7 months ago

@arjanhak I've raised a PR which I believe should fix this. Delegating to localhost is, I believe, fine to be doing here because we are just templating stuff to munge some variables; however not all of the section was run against localhost so it didn't fully work. It should now with my fix.