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

Filetree_create - extra_vars export issue #856

Open
przemkalit opened this issue Jul 5, 2024 · 1 comment
Open

Filetree_create - extra_vars export issue #856

przemkalit opened this issue Jul 5, 2024 · 1 comment
Labels
bug Something isn't working filetree/filetree_create new New issue, this should be removed once reviewed

Comments

@przemkalit
Copy link
Contributor

Summary

When filetree_create is executed, and job_templates or other objects capable of having extra_vars have a variable defined like variable_name: 'https://{{ ip }}', it doesn't escape the brackets, as with this example variable_name: '{{ ip }}'. In next step when using filetree_read, error occurs.

Issue Type

  • Bug Report

Ansible, Collection, Controller details

ansible --version

ansible [core 2.16.2]
  config file = None
  configured module search path = ['/home/runner/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.12/site-packages/ansible
  ansible collection location = /home/runner/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.12.1 (main, Dec 18 2023, 00:00:00) [GCC 13.2.1 20231205 (Red Hat 13.2.1-6)] (/usr/bin/python3)
  jinja version = 3.1.3
  libyaml = True

ansible-galaxy collection list
Collection              Version
----------------------- -------
ansible.posix           1.5.4
ansible.windows         2.2.0
awx.awx                 23.6.0
containers.podman       1.11.0
kubernetes.core         3.0.0
redhatinsights.insights 1.2.2
theforeman.foreman      4.0.0

Controller version  4.5.6 
  • ansible installation method: EE

OS / ENVIRONMENT

Red Hat

Desired Behavior

Object is exported with escaped brackets.

Actual Behavior

  1. Object is exported by the filetree_create
  2. Object is imported by the filetree_read
  3. Error occurs:
  "failed_when_result": "The conditional check ''VARIABLE IS NOT DEFINED' in __contents_filetree_controller_templates' failed. The error was: error while evaluating conditional ('VARIABLE IS NOT DEFINED' in __contents_filetree_controller_templates): {'ansible_included_var_files': ['/repo_dir/casc/controller_job_templates/5177_EXAMPLE - customer  template.yaml'], 'ansible_facts': {'controller_templates': [{'name': 'EXAMPLE - customer  template', 'description': '', 'organization': 'uuc', 'project': 'ansible-project-CasC-target-example', 'inventory': 'localhost', 'playbook': 'playbook.yaml', 'scm_branch': '', 'forks': 0, 'limit': '', 'verbosity': 0, 'job_type': 'run', 'job_slice_count': 1, 'use_fact_cache': False, 'allow_simultaneous': False, 'ask_scm_branch_on_launch': False, 'ask_diff_mode_on_launch': False, 'ask_tags_on_launch': False, 'ask_skip_tags_on_launch': False, 'ask_job_type_on_launch': False, 'ask_verbosity_on_launch': False, 'ask_variables_on_launch': False, 'ask_inventory_on_launch': False, 'ask_limit_on_launch': False, 'ask_credential_on_launch': False, 'ask_execution_environment_on_launch': False, 'ask_labels_on_launch': False, 'ask_forks_on_launch': False, 'ask_job_slice_count_on_launch': False, 'ask_timeout_on_launch': False, 'ask_instance_groups_on_launch': False, 'extra_vars': {'ip': 'https://{{ ip_d }}/files'}, 'job_tags': '', 'force_handlers': False, 'skip_tags': '', 'start_at_task': '', 'timeout': 0, 'host_config_key': '', 'survey_enabled': False, 'become_enabled': False, 'diff_mode': False, 'webhook_service': '', 'prevent_instance_group_fallback': False}]}, '_ansible_no_log': False, 'failed': False, 'changed': False}: 'ip_d' is undefined. 'ip_d' is undefined. {'ansible_included_var_files': ['/repo_dir/casc/controller_job_templates/5177_EXAMPLE - customer  template.yaml'], 'ansible_facts': {'controller_templates': [{'name': 'EXAMPLE - customer  template', 'description': '', 'organization': 'uuc', 'project': 'ansible-project-CasC-target-example', 'inventory': 'localhost', 'playbook': 'playbook.yaml', 'scm_branch': '', 'forks': 0, 'limit': '', 'verbosity': 0, 'job_type': 'run', 'job_slice_count': 1, 'use_fact_cache': False, 'allow_simultaneous': False, 'ask_scm_branch_on_launch': False, 'ask_diff_mode_on_launch': False, 'ask_tags_on_launch': False, 'ask_skip_tags_on_launch': False, 'ask_job_type_on_launch': False, 'ask_verbosity_on_launch': False, 'ask_variables_on_launch': False, 'ask_inventory_on_launch': False, 'ask_limit_on_launch': False, 'ask_credential_on_launch': False, 'ask_execution_environment_on_launch': False, 'ask_labels_on_launch': False, 'ask_forks_on_launch': False, 'ask_job_slice_count_on_launch': False, 'ask_timeout_on_launch': False, 'ask_instance_groups_on_launch': False, 'extra_vars': {'ip': 'https://{{ ip_d }}/files'}, 'job_tags': '', 'force_handlers': False, 'skip_tags': '', 'start_at_task': '', 'timeout': 0, 'host_config_key': '', 'survey_enabled': False, 'become_enabled': False, 'diff_mode': False, 'webhook_service': '', 'prevent_instance_group_fallback': False}]}, '_ansible_no_log': False, 'failed': False, 'changed': False}: 'ip_d' is undefined. 'ip_d' is undefined",

STEPS TO REPRODUCE

  1. Create job template with extra vars - url: 'https://{{ ip }}'
  2. Export with filetree_create.
---
- name: Backup all objects
  hosts: localhost
  connection: local
  gather_facts: false
  vars:
    controller_oauthtoken: "{{ lookup('ansible.builtin.env', 'TOWER_OAUTH_TOKEN') }}"
    controller_hostname: "{{ lookup('ansible.builtin.env', 'TOWER_HOST') }}"
    controller_validate_certs: "{{ lookup('ansible.builtin.env', 'TOWER_VERIFY_SSL') }}"
  roles:
    - infra.controller_configuration.filetree_create
  1. Read the object with filetree_read
---
- name: Read all objects
  hosts: localhost
  connection: local
  gather_facts: false
  vars:
    controller_oauthtoken: "{{ lookup('ansible.builtin.env', 'TOWER_OAUTH_TOKEN) }}"
    controller_hostname: "{{ lookup('ansible.builtin.env', 'TOWER_HOST') }}"
    controller_validate_certs: "{{ lookup('ansible.builtin.env', 'TOWER_VERIFY_SSL') }}"
  tasks:
    - name: Include vars from control_vars directory
      ansible.builtin.include_vars:
        dir: "{{ dir_orgs_vars }}"
        extensions:
          - "yml"
          - "yaml"

    - ansible.builtin.include_role:
      name: infra.controller_configuration.filetree_read
@przemkalit przemkalit added bug Something isn't working new New issue, this should be removed once reviewed labels Jul 5, 2024
@przemkalit
Copy link
Contributor Author

I've managed to fix this issue with a workaround like this:

extra_vars:
      {{ current_job_templates_asset_value.extra_vars | from_yaml | to_nice_yaml(indent=2) | indent(width=6, first=False) | replace("{{", "{% raw %}{{{% endraw %}") | replace("}}", "{% raw %}}}{% endraw %}") }}

I know this may be a bit stupid but it works :).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working filetree/filetree_create new New issue, this should be removed once reviewed
Projects
None yet
Development

No branches or pull requests

2 participants