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
148 stars 165 forks source link

host module failing to operate due to FQDN issue #1563

Open Ricker42 opened 1 year ago

Ricker42 commented 1 year ago
SUMMARY

When using the theforeman.foreman.host module, it will not execute if the name parameter is not a FQDN. However, not all hosts are always listed that way in the database, so when it attempts to identify the content host via lookup it fails to find it and thus does not execute the requested function

ISSUE TYPE
ANSIBLE VERSION
ansible [core 2.13.3]
  config file = /home/rgreene/ansible/satellite/ansible.cfg
  configured module search path = ['/home/rgreene/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /home/rgreene/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.13 (main, Nov  9 2022, 13:16:24) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
  jinja version = 3.1.2
  libyaml = True
COLLECTION VERSION
Collection         Version
------------------ -------
theforeman.foreman 3.8.0  
KATELLO/FOREMAN VERSION
tfm-rubygem-katello-4.3.0.50-1.el7sat.noarch
foreman-3.1.1.25-1.el7sat.noarch
STEPS TO REPRODUCE
[content_hosts]
rgreene-rhel79.tamlab.rdu2.redhat.com  content_host=rgreene-rhel79
---
- name: Remove host from Satellite inventory
  hosts: content_hosts
  gather_facts: yes
  become: yes

  vars:
    old_satellite: "sat6.******.com"

  vars_files:
    - satpass.yml

  tasks:

    - name: Remove host from old Satellite
      theforeman.foreman.host:
        password: "{{ satpassword }}"
        username: "{{ satuser }}"
        server_url: "https://{{ old_satellite }}"
        name: "{{ content_host }}"
        state: absent
        validate_certs: false
EXPECTED RESULTS

End result of the playbook should be the content-host "test-server" being removed from foreman/katello

ACTUAL RESULTS
ansible-playbook -vvvv --diff --ask-vault-password -i sat.inventory.yml remove_host.yml
[ansible.log](https://github.com/theforeman/foreman-ansible-modules/files/10828198/ansible.log)
Ricker42 commented 1 year ago

I was able to run the playbook successfully by modifying my ~/.ansible/collections/ansible_collections/theforeman/foreman/plugins/modules/host.py file to comment out the following lines (lines 461-462 in my version): if '.' not in module.foreman_params['name']: module.fail_json(msg="The hostname must be FQDN")