Hi, I would like to ensure that an item is in a list. For that I can use update: yes:
- name: Test
hosts: [localhost]
gather_facts: no
roles:
- kwoodson.yedit
tasks:
- name: Modify YAML
yedit:
content:
foo: bar
users:
- alice
key: users
value: "bob"
update: yes
# append: yes
state: present
register: res
- debug: var=res
However, this does not work when the list 'users' doesn't exist. It just succeeds without doing anything. If I use append: yes instead, it will create the list if neccessary. But then I get duplicates if the item does exist.
I think the source of this difference is that append has the following code, but update doesn't:
Hi, I would like to ensure that an item is in a list. For that I can use
update: yes
:However, this does not work when the list 'users' doesn't exist. It just succeeds without doing anything. If I use
append: yes
instead, it will create the list if neccessary. But then I get duplicates if the item does exist.I think the source of this difference is that
append
has the following code, butupdate
doesn't:https://github.com/kwoodson/ansible-role-yedit/blob/0ae7b9c9803fc8664a62a07bec72b338fe2a0846/library/yedit.py#L622-L624
Could this be added to
update
, or is there another way to achive this?