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

compute_resource - Internal server error after foreman update #1017

Closed fgoebel closed 4 years ago

fgoebel commented 4 years ago
SUMMARY

After an update of Foreman-apt-packages, the module compute_resource leads to Foreman internal server error, see verbose output below. This is the second time that I have these Issues after an update.

At the first time i just added another new compute-resource with the same settings but different name, migrated the tied virtual machines to the new one, deleted the old and renamed the compute-resource. As i do not want to go through this step every time I update some foreman-packages i want to check what is going on here

Foreman is installed on Ubuntu 18.04 with provided apt packages. To better understand how Foreman works we installed Foreman "on our own" with ansible and we did not use the foreman-installer.

I am not sure if this is even a problem with the ansible-module at the first place, but this is where I start... If you have some comments or ideas what this is causing and what i can do about it i would be quite happy!

What is striking to me is the line "message": "uninitialized constant Fog::Vsphere::Compute::ResourcePool" in the verbose output below, but i have not that much knowledge in ruby that i know what i should do about it.

Thank you very much for the foreman-ansible-modules as i really use them a lot and the work quite well. I have completely automated our foreman-setup and configuration with ansible with only compute-profiles and host-groups left to do.

My Background is mainly sys-admin stuff and I have not done that much development in my life..

I have redacted some information, so maybe some org-names may not match..

ISSUE TYPE
ANSIBLE VERSION
ansible 2.9.13
  config file = /home/fgoebel/Projekte/ansible-playbook-foreman-poc/ansible.cfg
  configured module search path = ['/home/fgoebel/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/fgoebel/.local/lib/python3.6/site-packages/ansible
  executable location = /home/fgoebel/.local/bin/ansible
  python version = 3.6.9 (default, Jul 17 2020, 12:50:27) [GCC 8.4.0]
KATELLO/FOREMAN VERSION
~$ apt show foreman
Package: foreman
Version: 2.1.3-1

katello is not installed

APYPIE VERSION
Version: 0.2.2
STEPS TO REPRODUCE

I am not quite sure what caused this issue, so it is difficult to tell the steps to reproduce this. Instead i will show what I have done before this happend.

I updated the apt packages for foreman from 2.1.2 to 2.1.3 with apt upgrade and ran the commands mentioned in the manual at Point 3 A like this:

---
# file: update.yml

- name: "Update all packages on all machines"
  hosts: all
  remote_user: adu
  become: true
  tasks:

    - name: "Update Package Caches - apt"
      apt:
        update_cache: yes
        cache_valid_time: 3600
      when: ansible_os_family == 'Debian'

    - name: "Upgrade Packages - apt"
      apt:
        upgrade: dist
      when: ansible_os_family == 'Debian'

    - name: "Upgrade Packages - dnf"
      dnf:
        name: "*"
        state: latest
      when:
        - ansible_os_family == 'RedHat'
        - ansible_distribution_major_version == '8'

- name: Run Foreman after upgrade tasks
  hosts: foreman
  remote_user: adu
  tasks:
      # https://theforeman.org/manuals/2.1/index.html#3.6Upgrade
    - name: run foreman after upgrade tasks
      command:
        cmd: "/usr/sbin/foreman-rake {{ item }}"
      loop:
        - "db:migrate"
        - "db:seed"
        - "apipie:cache"
        - "tmp:cache:clear"
        - "db:sessions:clear"
      become: true
      become_user: foreman

Snipped from playbook with regarding task:

Playbook example:

- name: Foreman-Config
  hosts: foreman
  remote_user: adu
  vars:
    foreman_config_role_enabled: True
  roles:
    - role: ansible-role-foreman-config
      tags: foreman
      delegate_to: localhost

excerpt from ansible-role-foreman-config tasks.yml

# Vmware Compute Ressource
# Docs: https://theforeman.github.io/foreman-ansible-modules/v1.0.1/modules/compute_resource_module.html#compute-resource-module
- name: Create Compute Resources
  theforeman.foreman.compute_resource:
    username: "{{ foreman_web_user }}"
    password: "{{ foreman_web_password }}"
    server_url: "{{ foreman_server }}"
    validate_certs: "{{ foreman_validate_certs }}"
    name: "{{ item.name }}"
    locations: "{{ item.locations }}"
    organizations: "{{ item.organizations }}"
    provider: "{{ item.provider }}"
    provider_params: "{{ item.provider_params }}"
    state: present
  no_log: True
  loop: "{{ foreman_compute_resources }}"
  loop_control:
    label: "{{ item.name }}"

snipped from defaults/main.yml from the role

---
# file: defaults/main.yml
# excerpt

# list of compute ressources to create
# provider_params depends on provider!!
foreman_compute_resources:
  - name: "Vcenter"
    locations:
      - "Company"
    organizations:
      - "Company"
    provider: vmware
    provider_params:
      url: "vcenter.example.com"
      user: user@fqdn
      password: ChangeMEPleaaase
      datacenter: "MCH"
EXPECTED RESULTS

Module runs successfully with "changed"

ACTUAL RESULTS
# Short:
failed: [mch005yx] (item=Vcenter) => {"ansible_loop_var": "item", "changed": false, "error": {"message": "uninitialized constant Fog::Vsphere::Compute::ResourcePool"}, "item": {"locations": ["Company"], "name": "Vcenter ", "organizations": ["Company"], "provider": "vmware", "provider_params": {"datacenter": "MCH", "password": "REDACTED", "url": "vcenter.example.com", "user": "admin@vsphere.local"}}, "msg": "Failed to show resource: 500 Server Error: Internal Server Error for url: https://foreman.example.com/api/compute_resources/2"}

# -vvvv
TASK [ansible-role-foreman-config : Create Compute Resources] ********************************************************************************
task path: /home/fgoebel/Projekte/ansible-playbook-foreman-poc/roles/ansible-role-foreman-config/tasks/tasks.yml:188
<localhost> ESTABLISH LOCAL CONNECTION FOR USER: fgoebel
<localhost> EXEC /bin/sh -c 'echo ~fgoebel && sleep 0'
<localhost> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/fgoebel/.ansible/tmp `"&& mkdir "` echo /home/fgoebel/.ansible/tmp/ansible-tmp-1602147261.3327305-1710678-174277109980429 `" && echo ansible-tmp-1602147261.3327305-1710678-174277109980429="` echo /home/fgoebel/.ansible/tmp/ansible-tmp-1602147261.3327305-1710678-174277109980429 `" ) && sleep 0'
Using module file /home/fgoebel/Projekte/ansible-playbook-foreman-poc/collections/ansible_collections/theforeman/foreman/plugins/modules/compute_resource.py
<localhost> PUT /home/fgoebel/.ansible/tmp/ansible-local-1708815ldx3dg8n/tmpv2por6kh TO /home/fgoebel/.ansible/tmp/ansible-tmp-1602147261.3327305-1710678-174277109980429/AnsiballZ_compute_resource.py
<localhost> EXEC /bin/sh -c 'chmod u+x /home/fgoebel/.ansible/tmp/ansible-tmp-1602147261.3327305-1710678-174277109980429/ /home/fgoebel/.ansible/tmp/ansible-tmp-1602147261.3327305-1710678-174277109980429/AnsiballZ_compute_resource.py && sleep 0'
<localhost> EXEC /bin/sh -c '/usr/bin/python /home/fgoebel/.ansible/tmp/ansible-tmp-1602147261.3327305-1710678-174277109980429/AnsiballZ_compute_resource.py && sleep 0'
<localhost> EXEC /bin/sh -c 'rm -f -r /home/fgoebel/.ansible/tmp/ansible-tmp-1602147261.3327305-1710678-174277109980429/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
  File "/tmp/ansible_theforeman.foreman.compute_resource_payload_5gj4lpt2/ansible_theforeman.foreman.compute_resource_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 81, in inner
    return f(self, *args, **kwargs)
  File "/tmp/ansible_theforeman.foreman.compute_resource_payload_5gj4lpt2/ansible_theforeman.foreman.compute_resource_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 462, in show_resource
    return self._resource_call(resource, 'show', params)
  File "/tmp/ansible_theforeman.foreman.compute_resource_payload_5gj4lpt2/ansible_theforeman.foreman.compute_resource_payload.zip/ansible_collections/theforeman/foreman/plugins/module_utils/foreman_helper.py", line 446, in _resource_call
    return self._resource(resource).call(*args, **kwargs)
  File "/home/fgoebel/.local/lib/python3.6/site-packages/apypie/resource.py", line 30, in call
    return self.api.call(self.name, action, params, headers, options, data, files)
  File "/home/fgoebel/.local/lib/python3.6/site-packages/apypie/api.py", line 189, in call
    return self._call_action(action, params, headers, data, files)
  File "/home/fgoebel/.local/lib/python3.6/site-packages/apypie/api.py", line 198, in _call_action
    headers, data, files)
  File "/home/fgoebel/.local/lib/python3.6/site-packages/apypie/api.py", line 224, in http_call
    request.raise_for_status()
  File "/home/fgoebel/.local/lib/python3.6/site-packages/requests/models.py", line 941, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
failed: [mch005yx] (item=Vcenter) => {
    "ansible_loop_var": "item",
    "changed": false,
    "error": {
        "message": "uninitialized constant Fog::Vsphere::Compute::ResourcePool"
    },
    "invocation": {
        "module_args": {
            "description": null,
            "locations": [
                "Muenchen"
            ],
            "name": "Vcenter",
            "organizations": [
                "Company"
            ],
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "provider": "vmware",
            "provider_params": {
                "app_ident": null,
                "caching_enabled": null,
                "datacenter": "MCH",
                "display_type": null,
                "email": null,
                "key_path": null,
                "ovirt_quota": null,
                "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
                "project": null,
                "region": null,
                "ssl_verify_peer": null,
                "tenant": null,
                "url": "vcenter.example.com",
                "use_v4": null,
                "user": "admin@vsphere.local",
                "zone": null
            },
            "server_url": "https://foreman.fmtest.example.com",
            "state": "present",
            "updated_name": null,
            "username": "ansible",
            "validate_certs": false
        }
    },
    "item": {
        "locations": [
            "Muenchen"
        ],
        "name": "Vcenter",
        "organizations": [
            "Company"
        ],
        "provider": "vmware",
        "provider_params": {
            "datacenter": "MCH",
            "password": "REDACTED",
            "url": "vcenter.example.com",
            "user": "admin@vsphere.local"
        }
    },
    "msg": "Failed to show resource: 500 Server Error: Internal Server Error for url: https://foreman.fmtest.example.com/api/compute_resources/2"
}
evgeni commented 4 years ago

This looks like an issue with your installation and not with the Ansible modules. I would expect you can't create a compute resource in the WebUI either.

fgoebel commented 4 years ago

I just ran this playbook again today and it just works again. So yes I think you are right this i more a problem with my installation.

Thank you for your feedback and providing these modules!