ansible: no se puede agregar a una lista en un bucle with_items
tome este libro de jugadas por ejemplo:
---
- hosts: localhost
gather_facts: no
vars:
in_list:
- value1
- value2
- value3
final_list: []
tasks:
- debug:
var: in_list
- name: parse list
set_fact:
final_list: "{{ final_list + [{'key': item}] }}"
with_items: "{{ in_list }}"
- debug:
var: final_list
parece que elfinal_list
se reemplaza en cada iteración por el último reemplazo de set_fact, es decir, no se agrega a él en cada bucle.
salida:
[root@optima-ansible ILIAS]# ansible-playbook append_to_list.yml
PLAY [localhost] ****************************************************************************************************************************************************************************************************
TASK [debug] ********************************************************************************************************************************************************************************************************
ok: [localhost] => {
"in_list": [
"value1",
"value2",
"value3"
]
}
TASK [parse list] ***************************************************************************************************************************************************************************************************
ok: [localhost] => (item=value1)
ok: [localhost] => (item=value2)
ok: [localhost] => (item=value3)
TASK [debug] ********************************************************************************************************************************************************************************************************
ok: [localhost] => {
"final_list": [
{
"key": "value3"
}
]
}
PLAY RECAP **********************************************************************************************************************************************************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
[root@optima-ansible ILIAS]#
utilicé el código de estopregunta
¿Qué estoy haciendo mal?
actualización: mi configuración:
[root@optima-ansible ILIAS]# ansible --version
ransible 2.5.1
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.14 (default, Mar 14 2018, 13:36:31) [GCC 7.3.1 20180303 (Red Hat 7.3.1-5)]
[root@optima-ansible ILIAS]# rpm -qa --last | grep ansible
ansible-2.5.1-1.fc27.noarch Sun 22 Apr 2018 02:46:30 AM EEST
[root@optima-ansible ILIAS]#