ansible / ansible

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.
https://www.ansible.com/
GNU General Public License v3.0
62.49k stars 23.83k forks source link

Append list element works different between core 2.11.12 and 2.14.14 #83940

Closed vpelagatti closed 2 weeks ago

vpelagatti commented 2 weeks ago

Summary

I'm migrating OS from CentOS 7 to Oracle Linux 9. When I execute the current playbook on CentOS 7 reporting:

ansible --version ansible [core 2.11.12] config file = /home/vpelagatti/local/ansible-deploy-scooby/envs/dev1/ansible.cfg configured module search path = ['/usr/share/ansible', '/home/vpelagatti/local/ansible-deploy-scooby/envs/dev1/library'] ansible python module location = /home/vpelagatti/local/virtual-environments/unix-hosting-dev1/lib/python3.6/site-packages/ansible ansible collection location = /home/vpelagatti/local/ansible-deploy-scooby/envs/dev1/collections executable location = /home/vpelagatti/local/virtual-environments/unix-hosting-dev1/bin/ansible python version = 3.6.12 (default, Sep 15 2020, 12:49:50) [GCC 4.8.5 20150623 (Red Hat 4.8.5-37)] jinja version = 3.0.3 libyaml = True

I got the expected results but when I use core version 2.14.14 the list element didn't add to mr list.

I'll appreciate any help if I'm doing something wrong

Thank you very much!

Issue Type

Bug Report

Component Name

core

Ansible Version

$ ansible --version
ansible [core 2.14.14]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.18 (main, Jul  3 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3.0.1)] (/usr/bin/python3)
  jinja version = 3.1.2
  libyaml = True

Configuration

# if using a version older than ansible-core 2.12 you should omit the '-t all'
$ ansible-config dump --only-changed -t all
DEV1 dev1vuxorclldap01 ~# ansible-config dump --only-changed -t all
CONFIG_FILE() = /etc/ansible/ansible.cfg

OS / Environment

Red Hat Enterprise Linux release 9.4 (Plow)

Steps to Reproduce

- hosts: localhost

  gather_facts: no

  vars:
    mr: []
    master_replica: []
    opencurly: '{'
    closecurly: '}'
    doublequote: '"'

    LdapProviders: [
        { serverID: "1", pos: 0, rid: "201", hostname: "ldap01.test.com" },
        { serverID: "2", pos: 1, rid: "202", hostname: "ldap02.test.com" }
    ]

    LdapConsumers: [
        { serverID: "3", hostname: "ldap03.test.com" },
        { serverID: "4", hostname: "ldap04.test.com" }
    ]

    suffix: 'dc=suffix'
    dn: 'cn=test,{{ suffix }}'
    PWldap: "mskz?C9)4J:pB#S2+naK"

  tasks:
  - name: Create Providers hosts replication list in non-Prod environment
    set_fact:
      mr: "{{ mr }} + [ '{{ opencurly }}{{ item.0 }}{{ closecurly }}rid={{ item.1.rid }} provider=ldap://{{ item.1.hostname }} binddn={{ doublequote}}{{ dn }}{{ doublequote}} bindmethod=simple credentials={{ doublequote }}{{PWldap}}{{ doublequote }} searchbase={{ doublequote}}{{ suffix }}{{ doublequote}} type=refreshAndPersist interval=00:00:00:10 retry={{ doublequote}}5 5 60 +{{ doublequote}} timeout=1']"
    with_indexed_items:
      - "{{ LdapProviders }}"
    tags:
    - ldap

  - name: Print mr
    debug:
      msg: "{{ mr }}"

Expected Results

PLAY [localhost] ****

TASK [Create Providers hosts replication list in non-Prod environment] ** ok: [localhost] => (item=[0, {'serverID': '1', 'pos': 0, 'rid': '201', 'hostname': 'ldap01.test.com'}]) ok: [localhost] => (item=[1, {'serverID': '2', 'pos': 1, 'rid': '202', 'hostname': 'ldap02.test.com'}])

TASK [Print mr] ***** ok: [localhost] => { "msg": [ "{0}rid=201 provider=ldap://ldap01.test.com binddn=\"cn=test,dc=suffix\" bindmethod=simple credentials=\"mskz?C9)4J:pB#S2+naK\" searchbase=\"dc=suffix\" type=refreshAndPersist interval=00:00:00:10 retry=\"5 5 60 +\" timeout=1", "{1}rid=202 provider=ldap://ldap02.test.com binddn=\"cn=test,dc=suffix\" bindmethod=simple credentials=\"mskz?C9)4J:pB#S2+naK\" searchbase=\"dc=suffix\" type=refreshAndPersist interval=00:00:00:10 retry=\"5 5 60 +\" timeout=1" ] }

PLAY RECAP ** localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

Actual Results

PLAY [localhost] ********************************************************************************************************************************************************************************************************************************************************

TASK [Create Providers hosts replication list in non-Prod environment] **************************************************************************************************************************************************************************************************
ok: [localhost] => (item=[0, {'serverID': '1', 'pos': 0, 'rid': '201', 'hostname': 'ldap01.test.com'}])
ok: [localhost] => (item=[1, {'serverID': '2', 'pos': 1, 'rid': '202', 'hostname': 'ldap02.test.com'}])

TASK [Print mr] *********************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "msg": "[] + [ '{0}rid=201 provider=ldap://ldap01.test.com binddn=\"cn=test,dc=suffix\" bindmethod=simple credentials=\"mskz?C9)4J:pB#S2+naK\" searchbase=\"dc=suffix\" type=refreshAndPersist interval=00:00:00:10 retry=\"5 5 60 +\" timeout=1'] + [ '{1}rid=202 provider=ldap://ldap02.test.com binddn=\"cn=test,dc=suffix\" bindmethod=simple credentials=\"mskz?C9)4J:pB#S2+naK\" searchbase=\"dc=suffix\" type=refreshAndPersist interval=00:00:00:10 retry=\"5 5 60 +\" timeout=1']"
}

PLAY RECAP **************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Code of Conduct

ansibot commented 2 weeks ago

Files identified in the description:

None

If these files are incorrect, please update the component name section of the description or use the component bot command.

ansibot commented 2 weeks ago

@vpelagatti ansible-core 2.14 is not supported and no longer receives bug fixes. Please test against one of the supported versions of ansible-core, preferably the most recent one, to see whether the bug has been fixed.

click here for bot help

mkrizek commented 2 weeks ago

The change in behavior was intentional and documented at https://docs.ansible.com/ansible/latest/porting_guides/porting_guide_core_2.13.html#playbook.

vpelagatti commented 2 weeks ago

When I change to the documented way, both list elements were processed but only the second element variables were assigned: mr: "{{ mr + [ '{{ opencurly }}{{ item.0 }}{{ closecurly }}rid={{ item.1.rid }} provider=ldap://{{ item.1.hostname }} binddn={{ doublequote}}{{ dn }}{{ doublequote}} bindmethod=simple credentials={{ doublequote }}{{PWldap}}{{ doublequote }} searchbase={{ doublequote}}{{ suffix }}{{ doublequote}} type=refreshAndPersist interval=00:00:00:10 retry={{ doublequote}}5 5 60 +{{ doublequote}} timeout=1'] }}"

Output: `TASK [Create Providers hosts replication list in non-Prod environment] ** ok: [localhost] => (item=[0, {'serverID': '1', 'pos': 0, 'rid': '201', 'hostname': 'ldap01.test.com'}]) ok: [localhost] => (item=[1, {'serverID': '2', 'pos': 1, 'rid': '202', 'hostname': 'ldap02.test.com'}])

TASK [Print mr] ***** ok: [localhost] => { "msg": [ "{1}rid=202 provider=ldap://ldap02.test.com binddn=\"cn=test,dc=suffix\" bindmethod=simple credentials=\"mskz?C9)4J:pB#S2+naK\" searchbase=\"dc=suffix\" type=refreshAndPersist interval=00:00:00:10 retry=\"5 5 60 +\" timeout=1", "{{ opencurly }}{{ item.0 }}{{ closecurly }}rid={{ item.1.rid }} provider=ldap://{{ item.1.hostname }} binddn={{ doublequote}}{{ dn }}{{ doublequote}} bindmethod=simple credentials={{ doublequote }}{{PWldap}}{{ doublequote }} searchbase={{ doublequote}}{{ suffix }}{{ doublequote}} type=refreshAndPersist interval=00:00:00:10 retry={{ doublequote}}5 5 60 +{{ doublequote}} timeout=1" ] } `

vpelagatti commented 2 weeks ago

Thanks for the support. Because ansible 2.14 version reached its EOL, I'll change my development for that task