Hi,
- How would you append to a dict or list fact using `ansible_facts`
spanning multiple module calls?
- How can the result be used internally in another function of the module?
Let's say we have a module that is designed to be called multiple times,
like so, each time creating a new file with some content:
- name: Add Foo
mymodule:
name: foo
id: 1
content: "lorem ipsum"
- name: Add Bar
mymodule:
name: bar
id: 2
content: "dolor sit amet"
Each call to the module want to return a part of a dict using
`ansible_facts`:
facts = {mymodule: {id: name}}
module.exit_json(changed=True, ansible_facts=facts}
After these two calls, the fact should contain:
"mymodule": {
1: "foo"
2: "bar"
}
Following the additions, there's a final call to the module to trigger a
function that should write the fact to a index file.
(A more real world example could be that files in a directory not listed in
the fact, should be deleted)
- name: Save mymodule additions
mymodule:
save: /home/user/mymodule.txt
How should the facts be returned in order for them to be appended, and not
overwritten?
I'd rather not have use unique facts for each entry, e.g. `"mymodule_1" =
"Foo"`. Instead, I want to access the fact as a dict or list to be used
internally in the module.
I realise I may be overthinking this, but I'm new to Ansible module
development and I wasn't able find any examples on how module provided
facts should be used in a scenario like this.
Thanks!
- Tim
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/a57d79e7-649b-4ea3-a392-28f5c19cd35b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.