Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dshuffin opened this issue Nov 22, 2024 · 1 comment

Comments

@dshuffin
Copy link

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: ansible-collections/community.zabbix#1410

ISSUE TYPE
  • Bug Report
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'
@dshuffin
Copy link
Author

not an issue with ansible.netcommon. See discussion here: ansible/ansible#84374

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant