ansible / awx

AWX provides a web-based user interface, REST API, and task engine built on top of Ansible. It is one of the upstream projects for Red Hat Ansible Automation Platform.
Other
13.97k stars 3.41k forks source link

awx.awx.import module issue importing inventory_sources #13967

Open pombaer opened 1 year ago

pombaer commented 1 year ago

Please confirm the following

Bug Summary

I am using "awx.awx.import" like:

- name: "AWX | create inventory sources"
  awx.awx.import:
    assets: "{{ awx_inventory_sources.assets | to_json }}"
  environment:
    CONTROLLER_VERIFY_SSL: "{{ awx_cli_verify_ssl }}"
    CONTROLLER_HOST: "{{ awx_hostname }}"
    CONTROLLER_USERNAME: "{{ awx_username }}"
    CONTROLLER_PASSWORD: "{{ awx_password }}"

To import the following yaml:

assets:
  inventory_sources:
  - credential: null
    description: ''
    enabled_value: ''
    enabled_var: ''
    execution_environment:
      name: Custom AWX EE
      type: execution_environment
    host_filter: ''
    inventory:
      name: 'inv: ansible-staging'
      organization:
        name: Default
        type: organization
      type: inventory
    limit: ''
    name: "source inv: ansible-staging"
    natural_key:
      inventory:
        name: 'inv: ansible-staging'
        organization:
          name: Default
          type: organization
        type: inventory
      name: "source inv: ansible-staging"
      type: inventory_source
    overwrite: true
    overwrite_vars: true
    related:
      notification_templates_error: []
      notification_templates_started: []
      notification_templates_success: []
      schedules: []
    scm_branch: ''
    source: scm
    source_path: hosts.yml
    source_project:
      name: "git: inventory-staging"
      organization:
        name: Default
        type: organization
      type: project
    source_vars: '---'
    timeout: 0
    update_cache_timeout: 0
    update_on_launch: true
    verbosity: 1

The code workd if there is already an "Source" definition on the inventory, if the inventory does not contain an "Source" definition yet the following error occurs:

  msg: |-
    /api/v2/inventory_sources/ "source inv: ansible-staging": Bad Request (400) received - {'inventory': ['This field cannot be blank.']}.

AWX version

22.1.0

Select the relevant components

Installation method

kubernetes

Modifications

no

Ansible version

ansible [core 2.14.5]

Operating system

Debian 11.4

Web browser

No response

Steps to reproduce

Create a Inventory without a Source definition and try to import a inventory_source definition using "awx.awx.import", this should end in an error, after that manually create a Source definition for the inventory and try to import the same inventory_source definition , this time it should work.

The Object can be exported with "awx.awx.export".

Expected results

The inventory_source definition should be created and synchronized.

Actual results

Error is :

msg: |- /api/v2/inventory_sources/ "source inv: ansible-staging": Bad Request (400) received - {'inventory': ['This field cannot be blank.']}.

Additional information

No response

AlanCoding commented 1 year ago

I am suspecting this might be related to https://github.com/ansible/awx/issues/13973 ping @john-westcott-iv

john-westcott-iv commented 1 year ago

This may be fixed by #13977. @pombaer can you try the import with a modified version of awxkit per #13977 and let us know if it indeed fixed by that?

pombaer commented 1 year ago

I will test it, and let you know.

pombaer commented 1 year ago

I install latest awxkit (22.2.0) on the Node where AWX is installed. operator verison is "2.1.0" and installed "awx.awx" from awx galaxy where the ansible-playbook is run, version "22.2.0". The error is the same. :(

pombaer commented 1 year ago

I have opend a second issue: https://github.com/ansible/awx/issues/13996, I downgraded awx.awx collection and awxkit to 21.13.0 and everythin works as expected, also in this ticket, may ther is a newer version that works also, but something changed in newer versions breaking things.

john-westcott-iv commented 1 year ago

@pombaer My apologies for the confusion. This fix is not yet released. You would either need to use the devel version of AWX or manually modify the awxkit code like the above mentioned PR in order to test this. Also, as an FYI, these two issues are really the same because awx.awx.import just uses the awxkit library to perform the import. The issue is inside of the awxkit library as of the constructed inventory feature which is why it works in older versions of AWX.

john-westcott-iv commented 1 year ago

The fixes mentioned above have been released today with AWX. Please try with the new version and let us know if its working now.