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

Default source_project to organization for inventory source #10573

Merged
merged 1 commit into from
Jul 22, 2021

Conversation

Tompage1994
Copy link
Contributor

@Tompage1994 Tompage1994 commented Jul 1, 2021

SUMMARY

related #10571

Adds the defaulting of the source_project (when given) to be looked up under the organization selected in the same way the inventory is looked up.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME
  • awx_collection
AWX VERSION

awx_collection v19.2.2

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@awxbot awxbot added the type:bug label Jul 1, 2021
@beeankha beeankha added component:awx_collection issues related to the collection for controlling AWX state:in_progress labels Jul 1, 2021
@fosterseth
Copy link
Member

fosterseth commented Jul 1, 2021

this can be achieved more generally using our lookup plugin (albeit more verbose)
e.g.

tasks:
  - name: get project in org1
    set_fact:
        proj1: "{{ lookup('awx.awx.controller_api', 'projects', query_params={'name': 'Demo Project', 'organization__name':'org1'}, return_ids=True )}}"

  - name: create INVSOURCE
    inventory_source:
      name: inv1
      source: scm
      source_project: "{{ proj1 }}"
      organization: Default
      inventory: Demo Inventory

@Tompage1994 Tompage1994 force-pushed the collection_inv_src_proj branch from d042d1e to 59fd007 Compare July 2, 2021 08:02
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@Tompage1994
Copy link
Contributor Author

this can be achieved more generally using our lookup plugin (albeit more verbose)
e.g.

tasks:
  - name: get project in org1
    set_fact:
        proj1: "{{ lookup('awx.awx.controller_api', 'projects', query_params={'name': 'Demo Project', 'organization__name':'org1'}, return_ids=True )}}"

  - name: create INVSOURCE
    inventory_source:
      name: inv1
      source: scm
      source_project: "{{ proj1 }}"
      organization: Default
      inventory: Demo Inventory

I agree you can, but I think its much nicer to have it as part of the module as its something that fundamentally breaks at the moment if there are multiple projects under the same name without having to do the second call as you describe (This is also something you have to know to do and isn't necessarily intuitive to work out).

In much the same way as there is an organization field on this module to ensure the lookup of the inventory's org is correct, it surely makes sense to do the same thing for the project too?

@Tompage1994 Tompage1994 force-pushed the collection_inv_src_proj branch from 59fd007 to 638f6aa Compare July 6, 2021 15:05
@Tompage1994 Tompage1994 changed the title Enable selection of source_project_organization for inventory_source Defaults source_project to organization for inventory source Jul 6, 2021
@Tompage1994 Tompage1994 changed the title Defaults source_project to organization for inventory source Default source_project to organization for inventory source Jul 6, 2021
@Tompage1994
Copy link
Contributor Author

Have updated and removed the extra option and made it so we just default the project lookup to the organization

@beeankha
Copy link
Contributor

beeankha commented Jul 6, 2021

Hi @Tompage1994 , would you mind adding a task or two to the integration test playbook for the Inventory Source module? The test playbook can be found here: https://github.com/ansible/awx/blob/devel/awx_collection/tests/integration/targets/inventory_source/tasks/main.yml

@john-westcott-iv
Copy link
Member

When initially designed the collection was assuming that things would be defined together and that the returned id from one object could be used in the second object. For example:

tasks:
  - name: Create Organization
    tower_organization:
      name: Default
    register: my_default_org

- name: Create inventory
  tower_inventory:
    name: Demo Inventory
    organization: "{{ my_default_org.id }}"

In practice, there are times where things are not all defined at the same time or in the same playbook. So we added the ability to resolve by name but that introduced issues with non-unique instance of an objects. This is why we built the lookup plugin, so that you can resolve an objects name to its ID if the name is non-unique.

The problem with adding a new filed like this is that any object that has a dependency on another object could also require similar fields. For example take job_template, if we added fields like this we would need the following fields:
- credential_organization
- inventory_organization
- project_organization
- credentials_organization (this would somehow have to be in the credentials hash)

If I recall correctly there are one or two objects in Tower where a name and an org may not provide a unique ID as they can be a child of another non-unique object. So while it may be trivial in some modules, adding fields to identify uniqueness of Tower objects can be a very large task.

Also, as an FYI, it can be combined into a single step rather than two:

tasks:
  - name: create INVSOURCE
    inventory_source:
      name: inv1
      source: scm
      source_project: "{{ lookup('awx.awx.controller_api', 'projects', query_params={'name': 'Demo Project', 'organization__name':'org1'}, return_ids=True )}}"
      organization: Default
      inventory: Demo Inventory

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@Tompage1994 Tompage1994 changed the title Default source_project to organization for inventory source WIP: Default source_project to organization for inventory source Jul 6, 2021
@Tompage1994 Tompage1994 force-pushed the collection_inv_src_proj branch from 638f6aa to 6687d56 Compare July 7, 2021 12:26
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

Signed-off-by: tpage <tpage@redhat.com>
@Tompage1994 Tompage1994 force-pushed the collection_inv_src_proj branch from 6687d56 to 62fc62a Compare July 7, 2021 14:31
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@Tompage1994
Copy link
Contributor Author

@john-westcott-iv I completely take on board what you say here and I do agree entirely.

I've now changed this PR to address the fact that the module does fail if there are two projects of the same name. Now the project org will default to organization in the same way the inventory does. Hopefully this is something more useful. Speaking to @sean-m-sullivan, this functionality exists elsewhere.

I've also added something to the integration tests..

@Tompage1994 Tompage1994 changed the title WIP: Default source_project to organization for inventory source Default source_project to organization for inventory source Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:awx_collection issues related to the collection for controlling AWX type:bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants