# Add key to a List of dicts depending of a simple Array - Ansible Facts (package\_facts)

**URL:** <https://forum.ansible.com/t/add-key-to-a-list-of-dicts-depending-of-a-simple-array-ansible-facts-package-facts/28548>\
**Category:** Ansible Project\
**Created:** [September 11, 2018, 8:08am UTC](https://forum.ansible.com/t/add-key-to-a-list-of-dicts-depending-of-a-simple-array-ansible-facts-package-facts/28548 "2018-09-11T08:08:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucas.dagostino](https://avatars.discourse-cdn.com/v4/letter/l/b5a626/32.png) [@lucas.dagostino](https://forum.ansible.com/u/lucas.dagostino)\
**Post date:** [September 11, 2018, 8:08am UTC](https://forum.ansible.com/t/add-key-to-a-list-of-dicts-depending-of-a-simple-array-ansible-facts-package-facts/28548/1 "2018-09-11T08:08:37Z")

</div>

Hello everybody,

I’m currently working on generating report for each inventory host thanks to [ansible-cmdb](https://github.com/fboender/ansible-cmdb). This tool is great but I have a problem to modify some facts:

I use the **[_package\_facts_](https://docs.ansible.com/ansible/latest/modules/package_facts_module.html) module to register installed packages.** They are automatically registered in hostvars as a list of dicts like this (_ansible\_facts.packages_):

_“packages”: {_  
_“accountsservice”: [_  
_{_  
_“arch”: “amd64”,_  
_“name”: “accountsservice”,_  
_“source”: “apt”,_  
_“version”: “0.6.40-2ubuntu11.3”_  
_}_  
_],_  
_“acl”: [_  
_{_  
_“arch”: “amd64”,_  
_“name”: “acl”,_  
_“source”: “apt”,_  
_“version”: “2.2.52-3”_  
_}_  
_],_  
_“acpid”: [_  
_{_  
_“arch”: “amd64”,_  
_“name”: “acpid”,_  
_“source”: “apt”,_  
_“version”: “1:2.0.26-1ubuntu2”_  
_}_  
_]_

_}_

On the other side, I have a remote bash script which outputs **a simple list of package name** manually installed on the host. For each host, I want to compare the two list, if a package name is also in _ **ansible\_facts.packages** _, then add a key in packages fact for the desired package _“manual”: true_. Otherwise, and if possible, add _“manual”: false_. So, after comparison, facts should be set like this:

_“packages”: {_  
_“accountsservice”: [_  
_{_  
_“arch”: “amd64”,_  
_“name”: “accountsservice”,_  
_“source”: “apt”,_  
_“version”: “0.6.40-2ubuntu11.3”,_  
_ **“manual”: true** _

_}_  
_],_  
_“acl”: [_  
_{_  
_“arch”: “amd64”,_  
_“name”: “acl”,_  
_“source”: “apt”,_  
_“version”: “2.2.52-3”,_  
_ **“manual”: false** _

_}_  
_],_  
_…_

_}_

Do you think it is possible in a proper way? I’m a newbie concerning handling JSON datastructures with Ansible, that is why I will do a workaround with a Python script since I’m working since some days on a proper way (with no success).

It would be a big help/step if I know how to do it properly.  
Thanks in advance !

Have a nice day,

Lucas
