Inconsistent behaviour storing dictionaries as facts

I found this possible related topic: reports-not-updated-all-the-time
Foreman Version:
2.1.0-develop

Issue:
In a playbook which purpose is to collect company specific information, a set of set_fact tasks is not being pulled in foreman although a consecutive ‘debug’ statement shows the correct values

Plugins:
I’m using the patched version of the ansible callback to which I was pointed to in this post

Detailed Explanation:
consider the following playbook and it’s output where, as a test, I add a simple test dictionary to an (already existing, but at this point empty) dictionary and then add more info retrieved from the host:

- name: set_facts to text value (for debugging/testing)
  set_fact: 
    CSRoles: {'something': "text_value"}
  tags:
  - apps

- name: set_facts about ebestuur modules
  set_fact: 
    CSRoles: "{{ CSRoles | combine( { item.split(';')[0]: item.split(';')[1] }) }}"
  loop: "{{ ebestuur_modules.stdout_lines }}"
  tags:
  - apps

- name: set_facts about roles
  set_fact: 
    CSRoles: "{{ CSRoles | combine( { item.key: item.value }) }}"
  loop:
    - { key: 'NLP', value: "{{ nlpconf.stat.exists }}" }
    - { key: 'PAL', value: "{{ palconf.stat.exists }}" }
  tags:
  - apps

- name: Check var Applications
  debug:
    var: CSRoles
  tags:
  - never
  - debug

As you can see in the output below, the {‘something’: ‘text_value’} is present in the CSRoles dictionary as are values added by the subsequent modules.
However in The Foreman ONLY {‘something’: ‘text_value’} is visible.

If I comment the first tasks, the CSRoles variable is not visible in Foreman at all, something that works in other parts of the playbook. i.e:

- name: Insert {{ smbcfg.stdout }} in samba dict",
  set_fact:
    Samba: "{{ Samba | combine({smbcfgline.split(';')[0] | regex_replace(' ','_'): smbcfgline.split(';')[1]}) }}"    
  loop: "{{ smbcfg.stdout_lines }}"
  loop_control:
    loop_var: smbcfgline

I’m using both constructs (looping over the list of stdout_lines and looping over a manually constructed list in order to construct a new dictionary) with success in the same playbook…

The output:

TASK [set_facts to text value (for debugging/testing)] ****************************************************************************************************************************************************************************************
ok: [ostgenesiusrode]

TASK [set_facts about ebestuur modules] *******************************************************************************************************************************************************************************************************
ok: [ostgenesiusrode] => (item=notulenbeheer;true)
ok: [ostgenesiusrode] => (item=efacturen;true)
ok: [ostgenesiusrode] => (item=dossierbeheer;false)
ok: [ostgenesiusrode] => (item=postregistratie;true)

TASK [set_facts about roles] ******************************************************************************************************************************************************************************************************************
ok: [ostgenesiusrode] => (item={u'key': u'NLP', u'value': True})
ok: [ostgenesiusrode] => (item={u'key': u'PAL', u'value': True})

TASK [Check var Applications] *****************************************************************************************************************************************************************************************************************
ok: [ostgenesiusrode] => {
    "CSRoles": {
        "NLP": true, 
        "PAL": true, 
        "dossierbeheer": "false", 
        "efacturen": "true", 
        "notulenbeheer": "true", 
        "postregistratie": "true", 
        "something": "text_value"
    }
}

PLAY RECAP ************************************************************************************************************************************************************************************************************************************
ostgenesiusrode            : ok=9    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

All used variables are defined as dictionaries in a vars file

Hopefully I’m contributing development with these posts…

1 Like

I’ve moved it to Support because Development -> Releases is just to coordinate our releases.