ahuffman / sat6-create-hosts

An Ansible role to create new virtual and bare-metal hosts in Satellite 6.x. v2 of Satellite6 API is required.
MIT License
4 stars 7 forks source link

group inheritance does not work #1

Closed michaelsstuff closed 5 years ago

michaelsstuff commented 5 years ago

Hi,

I have trouble deplyong a host in a nested group. Deyploing within the parent group is no problem, but when I give him the subgroup it fails with something like this:

    "json": {
        "error": {
            "errors": {
                "architecture_id": [
                    "can't be blank"
                ],
                "medium_id": [
                    "can't be blank"
                ],
                "operatingsystem_id": [
                    "can't be blank"
                ],
                "ptable_id": [
                    "can't be blank unless a custom partition has been defined"
                ],
                "root_pass": [
                    "should be 8 characters or more",
                    "should not be blank - consider setting a global or host group default"
                ]
            },
            "full_messages": [
                "Operatingsystem can't be blank",
                "Architecture can't be blank",
                "Root password should be 8 characters or more",
                "Root password should not be blank - consider setting a global or host group default",
                "Partition Table can't be blank unless a custom partition has been defined",
                "Medium can't be blank"
            ],
            "id": null
        }

Even though all values are either set in the parent or overwritten in the subgroup.

ahuffman commented 5 years ago

@MSchietzsch can you give me some insight as to what the host group structure looks like so I can determine the root cause?

group1 parent
 |_ group2 nested
    |_ group3 nested under group2

I believe when I tested this code I was working with a parent host group and a single nested host group under it. Let me know and I'll see what I can do.

michaelsstuff commented 5 years ago

Sure, my struckture is only one level:

group1 parent |_ group2 nested

deploying in group1 works, in group2 not

ahuffman commented 5 years ago

Can you run the playbook with -v and post the results? Curious to see what you're getting in the task:

    - debug:
        var: "host_grp_qry.json.results[0].ancestry"
        verbosity: "1"
ahuffman commented 5 years ago

It also looks like we might need to set some more things based on inheritance:

    - name: "Set inherited Host Group facts"
      block:
        - name: "Set inherited Satellite6 Domain ID"
          set_fact:
            domain_id: "{{ inherited_host_grp_qry.json.domain_id }}"
          when:
            - "not host_grp_qry.json.results[0].domain_id"

        - debug:
            var: "domain_id"
            verbosity: "1"
      tags:
        - "inherited_host_group_facts"
  when:
    - "host_grp_qry.json.results[0].ancestry is defined"
    - "host_grp_qry.json.results[0].ancestry"
  tags:
    - "inherited_host_group_facts"

Looks like we're only setting domain_id

ahuffman commented 5 years ago

image Also wondering if you have all of these set in the parent host group or if you're setting them in the nested host group?

michaelsstuff commented 5 years ago

Can you run the playbook with -v and post the results?

TASK [ahuffman-sat6_create_hosts : debug] ***************************************************************************************************************************************************************************************************
ok: [localhost] => {
    "host_grp_qry.json.results[0].ancestry": "33"
}

Also wondering if you have all of these set in the parent host group or if you're setting them in the nested host group?

Both. It is all set in the parent group: group1

But some are overwritten by the child group: group2

ahuffman commented 5 years ago

@MSchietzsch Can you provide the playbook code you're executing to launch the role?

I have created a nested host group, and defined the architecture, OS, partition table, root pass, and media within that host group and do not have the problem.

My setup is as follows: Parent Host Group: RHEL7 Nested Host Group: RHEL7-nested (Appears in the UI as RHEL7/RHEL7-nested)

My variables are as follows for the playbook:

sat6_hosts:
  - name: testserver
    comment: testing sat6 provisioning
    host_group: RHEL7-nested
    location: my_location
    parameters:
      - name: example_param
        value: test123
      - name: test2
        value: more data
    compute_resource: my_compute_resource
    compute_profile: 1-Default

After some playing around, I was able to determine what you're probably doing wrong. The Host Group name should not be in the form "RHEL7/RHEL7-nested", but should be just "RHEL7-nested". I was able to reproduce the error when using RHEL7/RHEL7-nested VS. just RHEL7-nested. I've added a note to the docs, but I think that will fix your issue.

Please validate if modifying your host_group value fixes your issue. Thanks!

michaelsstuff commented 5 years ago

Due to another bug in satellite I can not test it right now, but will do once I got it working again. Question to your solution: How do I address Subgroups with the same name then? image

ahuffman commented 5 years ago

This is a great test, and after some further inspection of the sat6 API, I found a title field for host groups which does in fact correspond to the UI in the sense that they have the full-qualified (nested) name of the host group VS the name field I was previously using.

I've made some changes and pushed into the dev branch and have tested and got it fully working (I believe).

I tested the following scenarios for my host groups: RHEL7 (parent) - works RHEL7/RHEL7-nested - works RHEL7/test/RHEL7-nested - works

All nested scenarios seem to be fully-functional now with just a few changes in the code. I'll be merging this into master later on, as I have a few other things to go back in add in for another scenario I'm working at.