theforeman / foreman-ansible-modules

Ansible modules for interacting with the Foreman API and various plugin APIs such as Katello
GNU General Public License v3.0
149 stars 166 forks source link

`theforeman.foreman.host` not idempotent #1780

Open mamercad opened 2 months ago

mamercad commented 2 months ago
SUMMARY

theforeman.foreman.host not idempotent

ISSUE TYPE
ANSIBLE VERSION
❯ ansible --version
ansible [core 2.15.12]
  config file = redacted/ansible.cfg
  configured module search path = ['redacted/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = redacted/Library/Caches/pypoetry/virtualenvs/foreman-D9iN7Av3-py3.9/lib/python3.9/site-packages/ansible
  ansible collection location = redacted/.ansible/collections:/usr/share/ansible/collections
  executable location = redacted/Library/Caches/pypoetry/virtualenvs/foreman-D9iN7Av3-py3.9/bin/ansible
  python version = 3.9.19 (main, May 22 2024, 11:52:33) [Clang 15.0.0 (clang-1500.3.9.4)] (redacted/Library/Caches/pypoetry/virtualenvs/foreman-D9iN7Av3-py3.9/bin/python)
  jinja version = 3.1.4
  libyaml = True
COLLECTION VERSION
❯ ansible-galaxy collection list | grep fore
theforeman.foreman                       4.1.0
KATELLO/FOREMAN VERSION
$ dpkg -l | grep foreman
ii  foreman                           3.11.1-1+ubuntu2204                          amd64        Systems management web interface
ii  foreman-cli                       3.11.1-1+ubuntu2204                          all          metapackage providing hammer CLI for Foreman
ii  foreman-debug                     3.11.1-1+ubuntu2204                          all          provides support utility foreman-debug.
ii  foreman-dynflow-sidekiq           3.11.1-1+ubuntu2204                          all          package providing dynflow sidekiq services for Foreman
ii  foreman-installer                 3.11.1-1+ubuntu2204                          all          Automated puppet-based installer for The Foreman
ii  foreman-postgresql                3.11.1-1+ubuntu2204                          all          metapackage providing PostgreSQL dependencies for Foreman
ii  foreman-proxy                     3.11.1-1+ubuntu2204                          all          RESTful proxies for DNS, DHCP, TFTP, and Puppet
ii  foreman-redis                     3.11.1-1+ubuntu2204                          all          metapackage providing redis dependencies for Foreman
ii  foreman-service                   3.11.1-1+ubuntu2204                          all          package providing Foreman services running via puma
ii  ruby-foreman-discovery            24.0.1-1                                     all          Foreman Discovery Plugin
ii  ruby-foreman-puppet               7.0.0-1~fm3.11                               all          Foreman Puppet Plugin
ii  ruby-hammer-cli-foreman           3.11.0-1+ubuntu2204                          all          Foreman commands for Hammer
ii  ruby-hammer-cli-foreman-puppet    0.1.0-1+ubuntu2204                           all          Foreman Puppet plugin for Hammer CLI
STEPS TO REPRODUCE
# Just run the same play to create a host more than once
...
    - name: "Create host"
      tags: [foreman, config]
      delegate_to: localhost
      theforeman.foreman.host:
        name: "foo"
        hostgroup: "foogroup"
        location: "Default Location"
        mac: "de:ad:be:ef:de:ad"
        organization: "Default Organization"
        state: "present"
EXPECTED RESULTS

It should be idempotent ... should show that the host already exists and no changes were made, etc.

ACTUAL RESULTS
TASK [foreman : Create host] *****************************************************************************
Wednesday 18 September 2024  07:20:48 -0400 (0:00:00.039)       0:00:09.478 *** 
fatal: [redacted -> localhost]: FAILED! => changed=false 
  error:
    errors:
      name:
      - has already been taken
    full_messages:
    - Name has already been taken
    id: null
  msg: 'Error while performing create on hosts: 422 Client Error: Unprocessable Content for url: https://redacted/api/hosts'