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
147 stars 163 forks source link

Error while performing update on subnets #728

Closed ephracis closed 4 years ago

ephracis commented 4 years ago
SUMMARY

I am still seeing #428 on 071e59c1cc8a52574a9ab45d675b2bbd486e67c6.

ISSUE TYPE
ANSIBLE VERSION
ansible 2.9.5
  config file = /Users/chbr/repos/work/components/foreman/ansible.cfg
  configured module search path = ['/Users/chbr/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.7.6 (default, Dec 30 2019, 19:38:26) [Clang 11.0.0 (clang-1100.0.33.16)]
KATELLO/FOREMAN VERSION
tfm-rubygem-katello-3.14.1-1.el7.noarch
foreman-1.24.2-1.el7.noarch
APYPIE VERSION
Version: 0.2.1
STEPS TO REPRODUCE

Run the task foreman_subnet twice. First time is fine but second time, and every retry gives the same error.

Task file inside role:

- name: Create subnets
  foreman_subnet:
    username: admin
    password: "{{ foreman_admin_password }}"
    server_url: "{{ foreman_url }}"
    validate_certs: no
    state: "{{ item.state | default(omit) }}"
    name: "{{ item.name }}"
    network_type: "{{ item.network_type | default(omit) }}"
    dns_primary: "{{ item.dns_primary | default(omit) }}"
    dns_secondary: "{{ item.dns_secondary | default(omit) }}"
    domains: "{{ item.domains | default(omit) }}"
    gateway: "{{ item.gateway | default(omit) }}"
    network: "{{ item.network | default(omit) }}"
    cidr: "{{ item.cidr | default(omit) }}"
    mask: "{{ item.mask | default(omit) }}"
    from_ip: "{{ item.from_ip | default(omit) }}"
    to_ip: "{{ item.to_ip | default(omit) }}"
    boot_mode: "{{ item.boot_mode | default(omit) }}"
    ipam: "{{ item.ipam | default(omit) }}"
    dhcp_proxy: "{{ item.dhcp_proxy | default(omit) }}"
    tftp_proxy: "{{ item.tftp_proxy | default(omit) }}"
    discovery_proxy: "{{ item.discovery_proxy | default(omit) }}"
    dns_proxy: "{{ item.dns_proxy | default(omit) }}"
    remote_execution_proxies: "{{ item.remote_execution_proxies | default(omit) }}"
    vlanid: "{{ item.vlanid | default(omit) }}"
    mtu: "{{ item.mtu | default(omit) }}"
    organizations: "{{ item.organizations | default(omit) }}"
    locations: "{{ item.locations | default(omit) }}"
  loop: "{{ foreman_subnets }}"
  loop_control:
    label: "{{ item.name }}"

Variable used during tests:

foreman_subnets:
  - name: Production
    network: 10.100.50.0
    mask: 255.255.255.0
    gateway: 10.100.50.1
    from_ip: 10.100.50.100
    to_ip: 10.100.50.200
    boot_mode: DHCP
    vlanid: 1050
    mtu: 9000
    domains:
      - fabric.basalt.se
    dhcp_proxy: "{{ foreman_hostname }}"
    tftp_proxy: "{{ foreman_hostname }}"
    discovery_proxy: "{{ foreman_hostname }}"
    locations:
      - Default Location
      - Uppsala
    organizations:
      - Default Organization
EXPECTED RESULTS

A successful run first time, every time.

ACTUAL RESULTS

Here's the output with -vvvv:

The full traceback is:
  File "/var/folders/d0/bmn8x1693sv_fcgb8kbyv4s40000gn/T/ansible_foreman_subnet_payload_reb3iejo/ansible_foreman_subnet_payload.zip/ansible/module_utils/foreman_helper.py", line 626, in resource_action
    result = self._resource_call(resource, action, resource_payload, options=options, data=data, files=files)
  File "/var/folders/d0/bmn8x1693sv_fcgb8kbyv4s40000gn/T/ansible_foreman_subnet_payload_reb3iejo/ansible_foreman_subnet_payload.zip/ansible/module_utils/foreman_helper.py", line 316, in _resource_call
    return self._resource(resource).call(*args, **kwargs)
  File "/usr/local/lib/python3.7/site-packages/apypie/resource.py", line 30, in call
    return self.api.call(self.name, action, params, headers, options, data, files)
  File "/usr/local/lib/python3.7/site-packages/apypie/api.py", line 187, in call
    action.validate(params, data, files)
  File "/usr/local/lib/python3.7/site-packages/apypie/action.py", line 53, in validate
    self._validate(self.params, values, data, files)
  File "/usr/local/lib/python3.7/site-packages/apypie/action.py", line 74, in _validate
    raise MissingArgumentsError(message)
failed: [localhost] (item=Production) => {
    "ansible_loop_var": "item",
    "changed": false,
    "invocation": {
        "module_args": {
            "boot_mode": "DHCP",
            "cidr": null,
            "description": null,
            "dhcp_proxy": "foreman-chre-node1.vms.basalt.se",
            "discovery_proxy": "foreman-chre-node1.vms.basalt.se",
            "dns_primary": null,
            "dns_proxy": null,
            "dns_secondary": null,
            "domains": [
                "fabric.basalt.se"
            ],
            "from_ip": "10.100.50.100",
            "gateway": "10.100.50.1",
            "httpboot_proxy": null,
            "ipam": "DHCP",
            "locations": [
                "Default Location",
                "Uppsala"
            ],
            "mask": "255.255.255.0",
            "mtu": 9000,
            "name": "Production",
            "network": "10.100.50.0",
            "network_type": "IPv4",
            "organizations": [
                "Default Organization"
            ],
            "parameters": null,
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "remote_execution_proxies": null,
            "server_url": "https://10.110.0.219",
            "state": "present",
            "template_proxy": null,
            "tftp_proxy": "foreman-chre-node1.vms.basalt.se",
            "to_ip": "10.100.50.200",
            "updated_name": null,
            "username": "admin",
            "validate_certs": false,
            "vlanid": 1050
        }
    },
    "item": {
        "boot_mode": "DHCP",
        "dhcp_proxy": "foreman-chre-node1.vms.basalt.se",
        "discovery_proxy": "foreman-chre-node1.vms.basalt.se",
        "domains": [
            "fabric.basalt.se"
        ],
        "from_ip": "10.100.50.100",
        "gateway": "10.100.50.1",
        "locations": [
            "Default Location",
            "Uppsala"
        ],
        "mask": "255.255.255.0",
        "mtu": 9000,
        "name": "Production",
        "network": "10.100.50.0",
        "organizations": [
            "Default Organization"
        ],
        "tftp_proxy": "foreman-chre-node1.vms.basalt.se",
        "to_ip": "10.100.50.200",
        "vlanid": 1050
    }
}

MSG:

Error while performing update on subnets: The following required parameters are missing: subnet
evgeni commented 4 years ago

Thanks for the report!

Could you do me a favor and post the output of ansible-playbook --diff --check 728.yml in your environment?

ephracis commented 4 years ago
TASK [foreman : Create subnets] ************************************************
Thursday 12 March 2020  16:37:21 +0100 (0:00:00.033)       0:00:11.945 ********
--- before
+++ after
@@ -4,6 +4,7 @@
             "boot_mode": "DHCP",
             "cidr": 24,
             "dhcp_id": 1,
+            "discovery_id": 1,
             "domain_ids": [
                 1
             ],

changed: [localhost] => (item=Production)
evgeni commented 4 years ago

Cool, thanks! So that means discovery has a similar bug as REX (which we fixed in #428).

evgeni commented 4 years ago

Can't repro on a 1.22/3.12 setup, will try on 1.24/3.14 in a moment.

evgeni commented 4 years ago

nope, same. so it's not only the discovery proxy.

evgeni commented 4 years ago

and also not reproducible with the whole playbook you posted. super weird.

just checking, the discovery version you're running is tfm-rubygem-foreman_discovery-16.0.1?

could you provide us the raw output of curl -k -u admin:YOURPASSWORD https://10.110.0.219/api/subnets/SUBNET_ID

evgeni commented 4 years ago

Oh, and does it also happen when you erase ~/.cache/apypie/ on the system your Ansible runs on? It might have a badly cached apidoc, even tho 0.2.1 should work fine in that regard.

evgeni commented 4 years ago

Or is there no discovery plugin installed?

ephracis commented 4 years ago

Nope, not installed. Is it a requirement for the subnet module?

evgeni commented 4 years ago

No, but then setting discovery_proxy: "{{ item.discovery_proxy }} seems odd? And that breaks it as it tries to set it every run, but as it's not installed, it's not mentioned in the api documentation and then the module tries to submit an empty request leading to that error.

ephracis commented 4 years ago

Oh, right! That was a copy and paste from another environment. I guess I never thought of removing that line.

Well then I guess I can solve this problem on my end. Thanks for all the help!

evgeni commented 4 years ago

I actually think the module should have caught that and have an idea how, so reopened