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

Inventory fix #259

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from
Open

Inventory fix #259

wants to merge 3 commits into from

Conversation

snagoor
Copy link
Contributor

@snagoor snagoor commented Oct 20, 2024

What does this PR do?

Fixes the incorrect inventory generation when the user provided group names don't match with the expected groups in aap_setup_prep_inv_nodes variable.

How should this be tested?

Automated tests are preferred, but not always doable - especially for infrastructure. Include commands to run your new feature, and also post-run commands to validate that it worked. (please use code blocks to format code samples)

All details regarding this is provided in Issue #258

Is there a relevant Issue open for this?

Provide a link to any open issues that describe the problem you are solving.
resolves #258

Other Relevant info, PRs, etc

This PR is basically reverting the code changed in 8363732

@djdanielsson djdanielsson requested a review from branic October 21, 2024 13:12
@@ -2,15 +2,12 @@

{% for group_key in aap_setup_prep_inv_nodes %}

{%if group_key in groups %}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change, believe this would break the entire template, can you share how its breaking versus the examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sean-m-sullivan thank you for the review. It wasn't broken till now because the change in PR 8363732 is not yet included in current release i.e. 2.5.2.

Here is the code to test this one

  1. variables.yml (not a complete one, just including the important ones for testing this)
aap_setup_prep_inv_nodes:
  automationcontroller:
    ctr1.example.com:
    ctr2.example.com:
  database:
    db.example.com:
aap_setup_prep_inv_vars:
  automationcontroller:
    node_type: hybrid
    ignore_preflight_errors: true
  database:
    ignore_preflight_errors: true
  all:
    pg_database: "awx"
    pg_username: "awx"
    pg_sslmode: "prefer"
    receptor_listener_port: 27199
  1. inventory.j2 (part of the snippet from the actual code)
{% for group_key in aap_setup_prep_inv_nodes %}

{%if group_key in groups %}

[{{ group_key }}]
{% for node_key in aap_setup_prep_inv_nodes[group_key] %}
{{ node_key }}{% if aap_setup_prep_inv_nodes[group_key][node_key] is defined %} {{ aap_setup_prep_inv_nodes[group_key][node_key] }}{% endif %}

{% endfor %}

{% endif %}

{% endfor %}
  1. pr_test.yml (playbook to test on localhost)
---
- hosts: localhost
  connection: local
  gather_facts: false
  tasks:
    - name: Populate AAP setup.sh inventory file from template
      ansible.builtin.template:
        src: inventory.j2
        dest: inventory
        mode: "640"
  1. Run the code to test
# ansible-playbook -i localhost, -e "@vars.yml" pr_test.yml

This will result in a inventory file created with empty content because of the if jinja2 conditional.

  1. Remove the if and endif jinja conditional from the inventory.j2 and re-run the test to check the inventory file creation.

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