ansible-collections / ansible.netcommon

Ansible Network Collection for Common Code
GNU General Public License v3.0
143 stars 104 forks source link

Can't set ansible_httpapi_port to a variable when task is delegated to another host #677

Open dshuffin opened 16 hours ago

dshuffin commented 16 hours ago
SUMMARY

Can't set ansible_httpapi_port to a variable when task is delegated to another host Not sure if it's a collection issue or a ansible-core issue, so decided to start here. Actual real-life problem caused by this is explained here: https://github.com/ansible-collections/community.zabbix/issues/1410

ISSUE TYPE
COMPONENT NAME

ansible.netcommon.httpapi connection

ANSIBLE VERSION
ansible [core 2.17.6]
  config file = <>ansible.cfg
  configured module search path = ['<>/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = <>collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.10.12 (main, Nov  6 2024, 20:22:13) [GCC 11.4.0] (/usr/bin/python3)
  jinja version = 3.0.3
  libyaml = True
COLLECTION VERSION
Collection                               Version
---------------------------------------- -------
ansible.netcommon                        7.1.0
CONFIGURATION
OS / ENVIRONMENT
STEPS TO REPRODUCE
- name: test
  hosts: zpc01
  tasks:

    - name: Setting variable
      ansible.builtin.set_fact:
        test: 443

    - name: debug on host
      vars:
        ansible_connection: httpapi
        ansible_httpapi_port: "{{ test }}"
      debug:
        var: ansible_httpapi_port

    - name: debug with delegation without httpapi
      vars:
        ansible_httpapi_port: "{{ test }}"
      debug:
        var: ansible_httpapi_port
      delegate_to: localhost

    - name: debug with delegation
      vars:
        ansible_connection: httpapi
        ansible_httpapi_port: "{{ test }}"
      debug:
        var: ansible_httpapi_port
      delegate_to: localhost
EXPECTED RESULTS

All tasks succeed

ACTUAL RESULTS

Task that sets ansible_httpapi_port to a variable fails when task is delegated to another hosts and ansible_connection is set to httpapi

TASK [Setting variable] ***********************************************************************************************************************************************************************************************
ok: [zpc01]

TASK [debug on host] **************************************************************************************************************************************************************************************************
ok: [zpc01] =>
  ansible_httpapi_port: '443'

TASK [debug with delegation without httpapi] **************************************************************************************************************************************************************************
ok: [zpc01 -> localhost] =>
  ansible_httpapi_port: '443'

TASK [debug with delegation] ******************************************************************************************************************************************************************************************
fatal: [zpc01 -> localhost]: FAILED! =>
  msg: '''test'' is undefined'