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

"file not found" error when file lookup plugin 'errors' parameter set to ignore #15064

Open
5 of 11 tasks
GROwen opened this issue Apr 4, 2024 · 1 comment
Open
5 of 11 tasks

Comments

@GROwen
Copy link

GROwen commented Apr 4, 2024

Please confirm the following

  • I agree to follow this project's code of conduct.
  • I have checked the current issues for duplicates.
  • I understand that AWX is open source software provided for free and that I might not receive a timely response.
  • I am NOT reporting a (potential) security vulnerability. (These should be emailed to [email protected] instead.)

Bug Summary

When using the file lookup plugin to template a files contents the AWX job fails even with the errors='ignore'

We've setup a mechanism to add file contents to templates based on the presence of a file in directory. When the template step is defined in the playbook the errors (if a file is not found) are ignored (i.e. ...ignoring) however if the template step is defined in a role errors are not ignored.

I've pushed a scaffold to https://github.com/GROwen/awx-errors-not-ignored but also outlined it below.

Structure

.
├── bug-report.yml
└── roles
    ├── requirements.yml
    └── templating-role
        ├── files
        │   └── bug-report
        │       ├── environment_variables.yml
        │       └── templates
        │           └── test.yml.j2
        └── tasks
            └── main.yml

File contents

./bug-report.yml
---
-
  name: Playbook to reproduce error handling error.
  hosts: all
  gather_facts: false
  connection: local
  vars:
    project_name: bug-report
    present_variables_file: "{{ role_path }}/files/{{ project_name }}/environment_variables.yml"
    present_variables: "{{ lookup('file', present_variables_file, errors='ignore') }}"
    absent_variables_file: "{{ role_path }}/files/{{ project_name }}/absent_variables.yml"
    absent_variables: "{{ lookup('file', absent_variables_file, errors='ignore') }}"
  collections:
    - community.general

  tasks:
    - name: Set working directory
      set_fact:
        working_directory: "{{ project_name }}"
      tags:
        - always

    - name: Template files
      include_role:
        name: templating-role
        apply:
          tags:
            - always
./roles/requirements.yml
---
- src: VCS
  name: templating-role
./roles/templating-role/files/bug-report/environment_variables.yml
KEY=value
./roles/templating-role/files/bug-report/templates/test.yml.j2
---

project: {{ project_name }}
{{ present_variables }}

{{ absent_variables }}
./roles/templating-role/tasks/main.yml
---
- name: Template files
  template:
    src: "{{ item.src }}"
    dest: "{{ working_directory }}/{{ item.path | splitext | first }}"
    mode: preserve
    trim_blocks: no
  with_filetree: '{{ role_path }}/files/{{ project_name }}/templates'
  when: item.state == 'file'

- name: Pause for confirmation of file contents
  pause:
    minutes: 5

This mechanism has worked until recently

AWX version

AWX 23.6.0

Select the relevant components

  • UI
  • UI (tech preview)
  • API
  • Docs
  • Collection
  • CLI
  • Other

Installation method

kubernetes

Modifications

no

Ansible version

2.13.6

Operating system

Debian GNU/Linux 12 (bookworm)

Web browser

Safari

Steps to reproduce

  1. Execute the templating-role tasks using the include-role module

Expected results

An error is thrown because the absent_variables_file is not found but is ignored and the job completes successfully.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleError: An unhandled exception occurred while templating '{{ lookup('file', absent_variables_file, errors='ignore') }}'. Error was a <class 'ansible.errors.AnsibleOptionsError'>, original message: The 'file' lookup had an issue accessing the file '/runner/requirements_roles/sdp-tide-platform/files/bug-report/absent_variables.yml'. file not found, use -vvvvv to see paths searched
failed: [content-legislation-vic-gov-au-develop] (item={'root': '/runner/requirements_roles/sdp-tide-platform/files/bug-report/templates', 'path': '.test.yml.j2', 'state': 'file', 'src': '/runner/requirements_roles/sdp-tide-platform/files/bug-report/templates/.test.yml.j2', 'uid': 1000, 'gid': 0, 'owner': '1000', 'group': 'root', 'mode': '0777', 'size': 80, 'mtime': 1712035704.0, 'ctime': 1712035852.2879279}) => {"ansible_loop_var": "item", "changed": false, "item": {"ctime": 1712035852.2879279, "gi…
...ignoring

Actual results

An error is thrown and the job fails.

An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ansible.errors.AnsibleError: An unhandled exception occurred while templating '{{ lookup('file', absent_variables_file, errors='ignore') }}'. Error was a <class 'ansible.errors.AnsibleOptionsError'>, original message: The 'file' lookup had an issue accessing the file '/runner/requirements_roles/sdp-tide-platform/files/bug-report/absent_variables.yml'. file not found, use -vvvvv to see paths searched
failed: [content-legislation-vic-gov-au-develop] (item={'root': '/runner/requirements_roles/sdp-tide-platform/files/bug-report/templates', 'path': '.test.yml.j2', 'state': 'file', 'src': '/runner/requirements_roles/sdp-tide-platform/files/bug-report/templates/.test.yml.j2', 'uid': 1000, 'gid': 0, 'owner': '1000', 'group': 'root', 'mode': '0777', 'size': 80, 'mtime': 1712032380.0, 'ctime': 1712034523.8676915}) => {"ansible_loop_var": "item", "changed": false, "item": {"ctime": 1712034523.8676915, "gi…

Additional information

No response

@fosterseth
Copy link
Member

@GROwen do you experience this issue when running the playbook directly from command line (not through awx)? ideally using exact same ansible and collections modules versions

@fosterseth fosterseth self-assigned this Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants