Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not Export inventory hosts #7447

Closed
takezyou opened this issue Jun 26, 2020 · 15 comments
Closed

Can not Export inventory hosts #7447

takezyou opened this issue Jun 26, 2020 · 15 comments

Comments

@takezyou
Copy link

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"
               }
          },
@takezyou
Copy link
Author

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

@ryanpetrello
Copy link
Contributor

ryanpetrello commented Jun 26, 2020

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.

@takezyou
Copy link
Author

takezyou commented Jun 26, 2020

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

@jbradberry
Copy link
Member

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

@takezyou
Copy link
Author

@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?

@jbradberry
Copy link
Member

@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.

@takezyou
Copy link
Author

@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 ...

@wenottingham
Copy link
Contributor

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

@ryanpetrello
Copy link
Contributor

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.

@ryanpetrello
Copy link
Contributor

ryanpetrello commented Oct 2, 2020

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

@ryanpetrello
Copy link
Contributor

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

@one-t
Copy link
Contributor

one-t commented Oct 28, 2020

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.

@ryanpetrello
Copy link
Contributor

Okay @one-t, it's merged.

@tiagodread
Copy link
Contributor

tiagodread commented Oct 29, 2020

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"
               }
          }
     ]
}

@hacko2
Copy link

hacko2 commented Nov 30, 2021

@tiagodread How did you test the import? Tried pasting into git and it says "[WARNING]: Skipping 'inventory' as this is not a valid group definition" and nothing imported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests