Ansible-inventory unable to parse foreman.py

Problem:
Running “ansible-inventory --list -i foreman.py” fails with unable to parse /etc/ansible/foreman.py.

Expected outcome:
Inventory should be able to successfully parse gathering all the facts in foreman inventory.

Foreman and Proxy versions:
Foreman 1.19 & Katello 3.8

Foreman and Proxy plugin versions:
Latest plugin versions

Other relevant data:
All hosts in Foreman cause foreman.py unable to parse because of puppet facts. The parse shows that it failed on the first host. After clicking build on the first host and running the ‘foreman built’ command, the parse then fails on the second host. I had it working on Foreman 1.18 & Katello 3.7 with AWX (Tower) calling the Foreman inventory. Not sure if something changed in the latest update.

Terminal output
[WARNING]: * Failed to parse /etc/ansible/foreman.py with script plugin: Inventory script (/etc/ansible/foreman.py) had an execution error: Traceback (most recent call last): File "/etc/ansible/foreman.py", line 440, in <module> sys.exit(not ForemanInventory().run()) File "/etc/ansible/foreman.py", line 434, in run self.get_inventory() File "/etc/ansible/foreman.py", line 384, in get_inventory self.update_cache() File "/etc/ansible/foreman.py", line 332, in update_cache self.facts[dns_name] = self._get_facts(host) File "/etc/ansible/foreman.py", line 243, in _get_facts raise ValueError("More than one set of facts returned for '%s'" % host) ValueError: More than one set of facts returned for ... [WARNING]: * Failed to parse /etc/ansible/foreman.py with ini plugin: /etc/ansible/foreman.py:24: Expected key=value host variable assignment, got: __future__ [WARNING]: Unable to parse /etc/ansible/foreman.py as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available

production.log
2018-09-17T17:35:21 [app] [I] Started GET "/api/v2/hosts?per_page=250&page=1" for ipaddress at 2018-09-17 17:35:21 -0400 2018-09-17T17:35:21 79f32c00 [app] [I] Processing by Api::V2::HostsController#index as JSON 2018-09-17T17:35:21 79f32c00 [app] [I] Parameters: {"per_page"=>"250", "page"=>"1", "apiv"=>"v2"} 2018-09-17T17:35:23 79f32c00 [app] [I] Authorized user username(user) 2018-09-17T17:35:23 79f32c00 [app] [I] Current user set to username (admin) 2018-09-17T17:35:23 79f32c00 [app] [I] Rendering api/v2/hosts/index.json.rabl within api/v2/layouts/index_layout 2018-09-17T17:35:23 79f32c00 [app] [I] Rendered api/v2/hosts/index.json.rabl within api/v2/layouts/index_layout (559.3ms) 2018-09-17T17:35:23 79f32c00 [app] [I] Completed 200 OK in 2057ms (Views: 525.4ms | ActiveRecord: 64.1ms) 2018-09-17T17:35:23 [app] [I] Started GET "/api/v2/hosts/106?per_page=250&page=1" for ipaddress at 2018-09-17 17:35:23 -0400 2018-09-17T17:35:23 cd19d5d8 [app] [I] Processing by Api::V2::HostsController#show as JSON 2018-09-17T17:35:23 cd19d5d8 [app] [I] Parameters: {"per_page"=>"250", "page"=>"1", "apiv"=>"v2", "id"=>"106"} 2018-09-17T17:35:23 cd19d5d8 [app] [I] Current user set to username (admin) 2018-09-17T17:35:23 cd19d5d8 [app] [I] Rendering api/v2/hosts/show.json.rabl 2018-09-17T17:35:23 cd19d5d8 [app] [I] Rendered api/v2/hosts/show.json.rabl (86.9ms) 2018-09-17T17:35:23 cd19d5d8 [app] [I] Completed 200 OK in 99ms (Views: 74.3ms | ActiveRecord: 15.8ms) 2018-09-17T17:35:23 [app] [I] Started GET "/api/v2/hosts/106/facts?per_page=250&page=1" for 10.98.20.240 at 2018-09-17 17:35:23 -0400 2018-09-17T17:35:23 dcec6edb [app] [I] Processing by Api::V2::FactValuesController#index as JSON 2018-09-17T17:35:23 dcec6edb [app] [I] Parameters: {"per_page"=>"250", "page"=>"1", "apiv"=>"v2", "host_id"=>"106"} 2018-09-17T17:35:23 dcec6edb [app] [I] Current user set to username (admin) 2018-09-17T17:35:23 dcec6edb [app] [I] Rendering api/v2/fact_values/index.json.rabl within api/v2/layouts/index_layout 2018-09-17T17:35:23 dcec6edb [app] [I] Rendered api/v2/fact_values/index.json.rabl within api/v2/layouts/index_layout (0.4ms) 2018-09-17T17:35:23 dcec6edb [app] [I] Completed 200 OK in 15ms (Views: 4.1ms | ActiveRecord: 4.5ms) 2018-09-17T17:35:23 [app] [I] Started GET "/api/v2/hosts/103?per_page=250&page=1" for 10.98.20.240 at 2018-09-17 17:35:23 -0400 2018-09-17T17:35:23 dcd15fe5 [app] [I] Processing by Api::V2::HostsController#show as JSON 2018-09-17T17:35:23 dcd15fe5 [app] [I] Parameters: {"per_page"=>"250", "page"=>"1", "apiv"=>"v2", "id"=>"103"} 2018-09-17T17:35:24 dcd15fe5 [app] [I] Current user set to username (admin) 2018-09-17T17:35:24 dcd15fe5 [app] [I] Rendering api/v2/hosts/show.json.rabl 2018-09-17T17:35:24 dcd15fe5 [app] [I] Rendered api/v2/hosts/show.json.rabl (86.0ms) 2018-09-17T17:35:24 dcd15fe5 [app] [I] Completed 200 OK in 98ms (Views: 76.2ms | ActiveRecord: 12.9ms) 2018-09-17T17:35:24 [app] [I] Started GET "/api/v2/hosts/103/facts?per_page=250&page=1" for 10.98.20.240 at 2018-09-17 17:35:24 -0400 2018-09-17T17:35:24 75125cd0 [app] [I] Processing by Api::V2::FactValuesController#index as JSON 2018-09-17T17:35:24 75125cd0 [app] [I] Parameters: {"per_page"=>"250", "page"=>"1", "apiv"=>"v2", "host_id"=>"103"} 2018-09-17T17:35:24 75125cd0 [app] [I] Current user set to username (admin) 2018-09-17T17:35:24 75125cd0 [app] [I] Rendering api/v2/fact_values/index.json.rabl within api/v2/layouts/index_layout 2018-09-17T17:35:24 75125cd0 [app] [I] Rendered api/v2/fact_values/index.json.rabl within api/v2/layouts/index_layout (0.8ms)

I just confirmed that this works in Foreman 1.18 & Katello 3.7 from Forklift. Also testing Foreman 1.19 & Katello 3.8 from Forklift and that didn’t work.

Was able to get inventory to sync on Foreman 1.19 & Katello 3.8. The foreman.py script currently is not able to fetch all host facts of the host for some reason.
I’m using AWX to gather inventory and run playbook after provision. in awx_task container, i modified /usr/lib/python2.7/site-packages/awx/plugins/inventory/foreman.py on line 238 to the following
-if not self.want_facts:
+if self.want_facts:
This will force inventory to not gather the host facts and allow inventory sync.