title: Ansible package_facts: set facts by comparing with another simple list
body: <p>I'm currently working on generating report for each inventory host thanks to ansible-cmdb. This tool is great but I have a problem to modify some facts:</p>
  
  <p>I use the <a href="https://docs.ansible.com/ansible/latest/modules/package_facts_module.html" rel="nofollow noreferrer">package_facts</a> <strong>module to register installed packages</strong>. They are automatically registered in hostvars as a list of dicts like this (<em>ansible_facts.packages</em>):</p>
  
  <pre><code>"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"
          }
      ]}
  </code></pre>
  
  <p>On the other side, I have a remote bash <strong>script which outputs a simple list of package name manually installed on the host.</strong> For each host, I want to compare the two list, if a package name is also in <em>ansible_facts.packages</em>, then add a key in packages fact for the desired package <em>"manual": true</em>. Otherwise, and if possible, add <em>"manual": false</em>. So, after comparison, facts should be set like this:</p>
  
  <pre><code>"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
          }
      ],
  ...}
  </code></pre>
  
  <p>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).</p>
  
  <p>It would be a big help/step if I know how to do it properly.
  Thanks in advance !</p>