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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
Expand All @@ -13,7 +13,7 @@ repos:
# entry: "yamllint"
# types: [yaml]
- repo: https://github.com/ansible/ansible-lint.git
rev: v24.7.0
rev: v24.9.2
hooks:
# see discussions here about what arguments are used, and behavior
# https://github.com/ansible/ansible-lint/issues/649
Expand All @@ -29,7 +29,7 @@ repos:
- ansible-core>=2.13
- yamllint>=1.26,<2.0
- repo: https://github.com/DavidAnson/markdownlint-cli2
rev: v0.13.0
rev: v0.14.0
hooks:
- id: markdownlint-cli2
...
3 changes: 0 additions & 3 deletions roles/aap_setup_prepare/templates/inventory.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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.

[{{ 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 %}

{# output all the variables and their groups #}
Expand Down