Awx: Can not Export inventory hosts

Created on 26 Jun 2020  路  14Comments  路  Source: ansible/awx

ISSUE TYPE
  • Bug or Fix
SUMMARY

Inventory does not include the host when doing an awx export

ENVIRONMENT
  • AWX version: 13.0.0
  • AWX install method: docker on linux
  • Ansible version: 2.9.10
  • Operating System: CentOS8
  • AWX CLI version: 13.0.0
STEPS TO REPRODUCE
awx export --invetory 
  • Inventory does not include the hosts
EXPECTED RESULTS
  • Inventory contains the host
ACTUAL RESULTS
{
     "inventory": [
          {
               "name": "AnsibleServer",
               "description": "",
               "kind": "",
               "host_filter": null,
               "variables": "---",
               "insights_credential": null,
               "organization": {
                    "name": "Default",
                    "type": "organization"
               },
               "natural_key": {
                    "organization": {
                         "name": "Default",
                         "type": "organization"
                    },
                    "name": "AnsibleServer",
                    "type": "inventory"
               }
          },
          {
               "name": "Demo Inventory",
               "description": "",
               "kind": "",
               "host_filter": null,
               "variables": "",
               "insights_credential": null,
               "organization": {
                    "name": "Default",
                    "type": "organization"
               },
               "natural_key": {
                    "organization": {
                         "name": "Default",
                         "type": "organization"
                    },
                    "name": "Demo Inventory",
                    "type": "inventory"
               }
          },
cli medium bug

Most helpful comment

Hey! Sorry, meant to comment on this- at this point we'd like to test this post-merge. Once it's been merged just put it back in needs_test and we can verify.

All 14 comments

@chrismeyersfsu
I want to fix this myself.
Can I challenge you?

Hey @takezyou,

We'd love a PR 馃槃 !

I'll leave @chrismeyersfsu' name on this since he's ultimately one of the people who would probably review such a PR.

Thank you!!馃槉
OK!!
I'm creating a PR.
If I don't understand something, can I ask a question?

@takezyou I'm also able to answer questions, as I did the original work on this feature.

@jbradberry @chrismeyersfsu

{
     "inventory": [
          {
               "name": "Demo Inventory",
               "description": "",
               "kind": "",
               "host_filter": null,
               "variables": "---",
               "insights_credential": null,
               "organization": {
                    "name": "Default",
                    "type": "organization"
               },
               "related": {
                    "hosts": [
                         {
                              "name": "localhost",
                              "type": "host"
                         },
                         {
                              "name": "localhost_2",
                              "type": "host"
                         }
                    ],
                    "groups": [
                         {
                              "name": "test",
                              "type": "group"
                         },
                         {
                              "name": "test_2",
                              "type": "group"
                         }
                    ],
                    "root_groups": [
                         {
                              "name": "test",
                              "type": "group"
                         }
                    ]
               },
               "natural_key": {
                    "organization": {
                         "name": "Default",
                         "type": "organization"
                    },
                    "hosts": null,
                    "groups": null,
                    "name": "Demo Inventory",
                    "type": "inventory"
               }
          }
     ]
}

I could currently call in related.
But I couldn't import it. Do you have any good ideas?

@takezyou got your code somewhere we can see it?

Off the top of my head this related endpoint is a create/attach/detach one, so based on the way I did most of the other related endpoints like it, it would rely on hosts and groups being top-level exportable objects. You would need, I think, to make sure the page model for these have a natural key defined, and that they are added to the top-level exportable objects list and the page model names are added to the exportable relations list. I'm guessing you did natural key and exportable relations parts of this based on the data structure you pasted above, but you would need to actually export and import the underlying objects in order for these natural keys to have something for the algorithm to find when doing the attachments.

I'm not sure how much it makes sense to actually do it that way, though. It could be that these objects should be treated more like workflow nodes, created in-place and never shared, in which case they should primarily go in the exportable dependent objects list. Also, I believe that there are other questions that would have to be answered about what to do with hosts and groups from inventory sources.

@jbradberry
Thank you.
I created a PR.
I was able to understand the algorithm somewhat better. I certainly had to think about what to do with the host and the group, as you say ...

If the issue is that when you export only an inventory it does not export related hosts, we should probably just document that.

Is this a regression from the old unofficial Tower CLI tool? If that tooling supported this, then I think this is a regression, and we should support it too.

Looks to me like the old tower-cli tool exports the actual hosts (and groups) from the inventory:

tower-cli receive --inventory "Demo Inventory"
[
  {
    "asset_type": "inventory",
    "name": "Demo Inventory",
    "organization": "Default",
    "asset_relation": {
      "host": [
        {
          "name": "localhost",
          "variables": "ansible_connection: local\nansible_python_interpreter: '{{ ansible_playbook_python }}'"
        }
      ],
      "group": [],
      "inventory_source": [],
      "roles": [
        {
          "name": "Admin",
          "user": [],
          "team": []
        },
        {
          "name": "Update",
          "user": [],
          "team": []
        },
        {
          "name": "Ad Hoc",
          "user": [],
          "team": []
        },
        {
          "name": "Use",
          "user": [],
          "team": []
        },
        {
          "name": "Read",
          "user": [],
          "team": []
        }
      ]
    }
  }
]

So I'd classify this current issue report as a bug.

cc @elyezer

Hey @one-t can you provide some details on what got this kicked back to needs_test so @jbradberry can have a look?

Hey! Sorry, meant to comment on this- at this point we'd like to test this post-merge. Once it's been merged just put it back in needs_test and we can verify.

Okay @one-t, it's merged.

Hey verified that:

  • The exported file contains the hosts and groups 鉁旓笍
  • The user can import this inventory file exported 鉁旓笍

Inventory with host and group:

{
     "inventory": [
          {
               "name": "Web",
               "description": "Description",
               "kind": "",
               "host_filter": null,
               "variables": "---\nFoo: Bar",
               "insights_credential": null,
               "organization": {
                    "name": "Default",
                    "type": "organization"
               },
               "related": {
                    "hosts": [
                         {
                              "name": "Host 1",
                              "description": "description of host 1",
                              "enabled": true,
                              "instance_id": "",
                              "variables": "",
                              "inventory": {
                                   "organization": {
                                        "name": "Default",
                                        "type": "organization"
                                   },
                                   "name": "Web",
                                   "type": "inventory"
                              },
                              "related": {
                                   "groups": []
                              },
                              "natural_key": {
                                   "name": "Host 1",
                                   "inventory": {
                                        "organization": {
                                             "name": "Default",
                                             "type": "organization"
                                        },
                                        "name": "Web",
                                        "type": "inventory"
                                   },
                                   "type": "host"
                              }
                         }
                    ],
                    "groups": [
                         {
                              "name": "Group 1",
                              "description": "description of group 1",
                              "variables": "",
                              "inventory": {
                                   "organization": {
                                        "name": "Default",
                                        "type": "organization"
                                   },
                                   "name": "Web",
                                   "type": "inventory"
                              },
                              "related": {
                                   "hosts": [],
                                   "children": []
                              },
                              "natural_key": {
                                   "name": "Group 1",
                                   "inventory": {
                                        "organization": {
                                             "name": "Default",
                                             "type": "organization"
                                        },
                                        "name": "Web",
                                        "type": "inventory"
                                   },
                                   "type": "group"
                              }
                         }
                    ]
               },
               "natural_key": {
                    "organization": {
                         "name": "Default",
                         "type": "organization"
                    },
                    "name": "Web",
                    "type": "inventory"
               }
          }
     ]
}
Was this page helpful?
0 / 5 - 0 ratings