Callback from proxy fails with 403 when trying to create a host

Problem:

Unable to create a host with ansible

Expected outcome:

Host should get created

Foreman and Proxy versions:

Version 1.19.0

Foreman and Proxy plugin versions:

ansible 2.9.17
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/usr/local/ansible/modules/ansible-module-foreman’]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]

Distribution and version:

Other relevant data:

[root@nick ansible]# ansible-playbook -i inventory/AKL/hosts foremancreatehost.yml --limit ‘testnick2.nic.internal’ -vvvvvv
ansible-playbook 2.9.17
config file = /etc/ansible/ansible.cfg
configured module search path = [u’/usr/local/ansible/modules/ansible-module-foreman’]
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
host_list declined parsing /etc/ansible/inventory/AKL/hosts as it did not pass its verify_file() method
script declined parsing /etc/ansible/inventory/AKL/hosts as it did not pass its verify_file() method
auto declined parsing /etc/ansible/inventory/AKL/hosts as it did not pass its verify_file() method
Parsed /etc/ansible/inventory/AKL/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/site-packages/ansible/plugins/callback/default.pyc
Attempting to use ‘actionable’ callback.
Skipping callback ‘actionable’, as we already have a stdout callback.
Attempting to use ‘aws_resource_actions’ callback.
Attempting to use ‘cgroup_memory_recap’ callback.
Attempting to use ‘cgroup_perf_recap’ callback.
Attempting to use ‘context_demo’ callback.
Attempting to use ‘counter_enabled’ callback.
Skipping callback ‘counter_enabled’, as we already have a stdout callback.
Attempting to use ‘debug’ callback.
Skipping callback ‘debug’, as we already have a stdout callback.
Attempting to use ‘dense’ callback.
Skipping callback ‘dense’, as we already have a stdout callback.
Attempting to use ‘dense’ callback.
Skipping callback ‘dense’, as we already have a stdout callback.
Attempting to use ‘foreman’ callback.
Attempting to use ‘full_skip’ callback.
Skipping callback ‘full_skip’, as we already have a stdout callback.
Attempting to use ‘grafana_annotations’ callback.
Attempting to use ‘hipchat’ callback.
Attempting to use ‘jabber’ callback.
Attempting to use ‘json’ callback.
Skipping callback ‘json’, as we already have a stdout callback.
Attempting to use ‘junit’ callback.
Attempting to use ‘log_plays’ callback.
Attempting to use ‘logdna’ callback.
Attempting to use ‘logentries’ callback.
Attempting to use ‘logstash’ callback.
Attempting to use ‘mail’ callback.
Attempting to use ‘minimal’ callback.
Skipping callback ‘minimal’, as we already have a stdout callback.
Attempting to use ‘nrdp’ callback.
Attempting to use ‘null’ callback.
Skipping callback ‘null’, as we already have a stdout callback.
Attempting to use ‘oneline’ callback.
Skipping callback ‘oneline’, as we already have a stdout callback.
Attempting to use ‘osx_say’ callback.
Attempting to use ‘profile_roles’ callback.
Attempting to use ‘profile_tasks’ callback.
Attempting to use ‘say’ callback.
Attempting to use ‘selective’ callback.
Skipping callback ‘selective’, as we already have a stdout callback.
Attempting to use ‘skippy’ callback.
Skipping callback ‘skippy’, as we already have a stdout callback.
Attempting to use ‘slack’ callback.
Attempting to use ‘splunk’ callback.
Attempting to use ‘stderr’ callback.
Skipping callback ‘stderr’, as we already have a stdout callback.
Attempting to use ‘sumologic’ callback.
Attempting to use ‘syslog_json’ callback.
Attempting to use ‘timer’ callback.
Attempting to use ‘tree’ callback.
Attempting to use ‘unixy’ callback.
Skipping callback ‘unixy’, as we already have a stdout callback.
Attempting to use ‘yaml’ callback.
Skipping callback ‘yaml’, as we already have a stdout callback.

PLAYBOOK: foremancreatehost.yml ******************************************************************************************************************************************************
Positional arguments: foremancreatehost.yml
subset: testnick2.nic.internal
become_method: sudo
inventory: (u’/etc/ansible/inventory/AKL/hosts’,)
forks: 5
tags: (u’all’,)
verbosity: 6
connection: smart
timeout: 10
1 plays in foremancreatehost.yml

PLAY [all] ***************************************************************************************************************************************************************************
META: ran handlers

TASK [ansible-provision-foreman : Create a host] *************************************************************************************************************************************
task path: /etc/ansible/roles/ansible-provision-foreman/tasks/main.yml:1
ESTABLISH LOCAL CONNECTION FOR USER: root
EXEC /bin/sh -c ‘( umask 77 && mkdir -p “echo /tmp”&& mkdir “echo /tmp/ansible-tmp-1617279362.56-24332-23424257423845” && echo ansible-tmp-1617279362.56-24332-23424257423845="echo /tmp/ansible-tmp-1617279362.56-24332-23424257423845" ) && sleep 0’
Using module_utils file ansible_collections/theforeman/foreman/plugins/module_utils
Using module_utils file ansible_collections/theforeman
Using module_utils file ansible_collections/theforeman/foreman/plugins
Using module_utils file ansible_collections/theforeman/foreman
Using module_utils file ansible_collections
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/basic.py
Using module_utils file ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/_utils.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/text/formatters.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/validation.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/text/converters.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/pycompat24.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/init.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/text/init.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/six/init.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/_json_compat.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/_collections_compat.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/parameters.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/parsing/convert_bool.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/parsing/init.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/compat/selectors.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/_text.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/sys_info.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/process.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/compat/init.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/file.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/common/collections.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/compat/_selectors2.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/distro/init.py
Using module_utils file /usr/lib/python2.7/site-packages/ansible/module_utils/distro/_distro.py
Using module_utils file ansible_collections/theforeman/foreman/plugins/module_utils/_apypie
Using module file /root/.ansible/collections/ansible_collections/theforeman/foreman/plugins/modules/host.py
PUT /root/.ansible/tmp/ansible-local-24323W8wmQu/tmp8KjSDP TO /tmp/ansible-tmp-1617279362.56-24332-23424257423845/AnsiballZ_host.py
EXEC /bin/sh -c ‘chmod u+x /tmp/ansible-tmp-1617279362.56-24332-23424257423845/ /tmp/ansible-tmp-1617279362.56-24332-23424257423845/AnsiballZ_host.py && sleep 0’
EXEC /bin/sh -c ‘/usr/bin/python2 /tmp/ansible-tmp-1617279362.56-24332-23424257423845/AnsiballZ_host.py && sleep 0’
EXEC /bin/sh -c ‘rm -f -r /tmp/ansible-tmp-1617279362.56-24332-23424257423845/ > /dev/null 2>&1 && sleep 0’
The full traceback is:
WARNING: The below traceback may not be related to the actual failure.
File “/tmp/ansible_theforeman.foreman.host_payload_l2D7TQ/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py”, line 93, in inner
return f(self, *args, **kwargs)
File “/tmp/ansible_theforeman.foreman.host_payload_l2D7TQ/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py”, line 617, in connect
self.apply_apidoc_patches()
File “/tmp/ansible_theforeman.foreman.host_payload_l2D7TQ/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py”, line 627, in apply_apidoc_patches
self._patch_host_update()
File “/tmp/ansible_theforeman.foreman.host_payload_l2D7TQ/ansible_theforeman.foreman.host_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py”, line 398, in _patch_host_update
_host_update_taxonomy_param = next(x for x in _host_update[‘params’] if x[‘name’] == param)
fatal: [testnick2.nic.internal]: FAILED! => {
“changed”: false,
“invocation”: {
“module_args”: {
“activation_keys”: null,
“architecture”: “x86_64”,
“build”: true,
“comment”: null,
“compute_attributes”: {
“cpus”: 2,
“memory_mb”: 4096
},
“compute_profile”: “vmware”,
“compute_resource”: “vcenter.nic.internal”,
“config_groups”: null,
“content_source”: null,
“content_view”: null,
“domain”: null,
“enabled”: null,
“environment”: “nic”,
“hostgroup”: “Base Sever/Centos 7.8.2003”,
“image”: null,
“interfaces_attributes”: [
{
“attached_devices”: null,
“attached_to”: null,
“bond_options”: null,
“compute_attributes”: {
“domain”: “nic.internal”,
“interface”: “VMXNET3”,
“ip”: “192.168.10.103”,
“name”: “nic1”,
“network”: “niccorp-192.168.10_corp”,
“subnet”: “192.168.10.0”
},
“domain”: null,
“identifier”: null,
“ip”: null,
“ip6”: null,
“mac”: null,
“managed”: null,
“mode”: null,
“mtu”: null,
“name”: null,
“password”: null,
“primary”: true,
“provider”: null,
“provision”: true,
“subnet”: null,
“subnet6”: null,
“tag”: null,
“type”: “interface”,
“username”: null,
“virtual”: null
}
],
“ip”: null,
“kickstart_repository”: null,
“lifecycle_environment”: null,
“location”: null,
“mac”: null,
“managed”: true,
“medium”: null,
“name”: “testnick2.nic.internal”,
“openscap_proxy”: null,
“operatingsystem”: “Centos 7.8.2003”,
“organization”: null,
“owner”: “unix”,
“owner_group”: null,
“parameters”: null,
“password”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,
“provision_method”: null,
“ptable”: “Centos - LVM - / , swap”,
“puppet_ca_proxy”: “puppet-2.nic.internal”,
“puppet_proxy”: “puppet-2.nic.internal”,
“puppetclasses”: null,
“pxe_loader”: “PXELinux BIOS”,
“realm”: null,
“root_pass”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,
“server_url”: “http://foreman-1.nic.corp-apps.com”,
“state”: “present”,
“subnet”: null,
“subnet6”: null,
“username”: “admin”,
“validate_certs”: false
}
},
“msg”: "Failed to connect to Foreman server: StopIteration: "
}

PLAY RECAP ***************************************************************************************************************************************************************************
testnick2.nic.internal : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

403 Client Error: Forbidden for url: http://foreman-1.nic.corp-apps.com/api/v2/reports

Note:
If i use the curl command with the url with my credentials it works fine.

Role task:

  • name: “Create a host”
    theforeman.foreman.host:
    username: user
    password: password
    server_url: “{{ server_url }}”
    name: testnick2.home.test
    hostgroup: Base Sever/Centos 7.8.2003
    managed: true
    build: yes
    compute_profile: “{{ compute_profile }}”
    compute_resource: “{{ computer_resource }}”
    compute_attributes:
    cpus: 2
    memory_mb: 4096
    interfaces_attributes:
    • type: “interface”
      primary: true
      compute_attributes:
      name: nic1
      network: home
      interface: “VMXNET3”
      subnet: 192.168.10.1
      ip: 192.168.10.12
      domain: “{{ domain }}”
      provision: yes
      operatingsystem: Centos 7.8.2003
      architecture: x86_64
      pxe_loader: PXELinux BIOS
      puppet_ca_proxy: {{ puppet_ca_proxy }}
      puppet_proxy: {{ puppet_proxy }}
      root_pass: whatev3er
      environment: test
      ptable: Centos - LVM - / , swap
      owner: god
      state: present
      validate_certs: false
      delegate_to: localhost

Any ideas?

I have not installed the plugin on the foreman side as per the link below.

Do i need this for my code above to work??

https://www.theforeman.org/plugins/foreman_ansible/2.x/index.html

2.2 Plugin

If this is the first plugin you’re installing, please see the plugin repository section to set up the repository first.

You can use foreman-installer to install Foreman Ansible:

foreman-installer --enable-foreman-plugin-ansible --enable-foreman-proxy-plugin-ansible

To run Ansible playbooks as Job Templates, you will also need Remote Execution:

foreman-installer --enable-foreman-plugin-remote-execution --enable-foreman-proxy-plugin-remote-execution-ssh

Nick Tailor
nicktailor.com