Import_tasks unable to find relative file path

I am unable to execute the import_tasks with relative path.
Following is the task:

- name: Fetching power state of iDRAC
  ansible.builtin.import_tasks: _fetch_uri.yml
  vars:
    uri: "/redfish/v1/Chassis/System.Embedded.1?$select=PowerState"
  until: idrac_output.json.PowerState == "Off"
  retries: 10
  delay: 30

This task returns the following error:

[ERROR]: Could not find or access ‘/home/Trisha/JIRA/new/ansible_collections/dellemc/openmanage/tests/output/.tmp/integration/idrac_redfish_powerstate-txpwuy60-ÅÑŚÌβŁÈ/tests/integration/idrac_redfish_powerstate/tests/_fetch_uri.yml’ on the Ansible Controller: Unable to retrieve file contents.
Could not find or access ‘/home/Trisha/JIRA/new/ansible_collections/dellemc/openmanage/tests/output/.tmp/integration/idrac_redfish_powerstate-txpwuy60-ÅÑŚÌβŁÈ/tests/integration/idrac_redfish_powerstate/tests/_fetch_uri.yml’ on the Ansible Controller.
If you are using a module and expect the file to exist on the remote, see the remote_src option: [Errno 2] No such file or directory: ‘/home/Trisha/JIRA/new/ansible_collections/dellemc/openmanage/tests/output/.tmp/integration/idrac_redfish_powerstate-txpwuy60-ÅÑŚÌβŁÈ/tests/integration/idrac_redfish_powerstate/tests/_fetch_uri.yml’

This task works fine in Ansible 2.18.

FYR:

I was able to reproduce the issue. In 2.18, this was working because the value here is templated: ansible/lib/ansible/playbook/helpers.py at stable-2.18 · ansible/ansible · GitHub. In 2.19, that value is no longer templated: ansible/lib/ansible/playbook/helpers.py at stable-2.19 · ansible/ansible · GitHub. I think the change is a bug.

I’ve opened a pull request to get additional opinions: Fix nested import_tasks when the parent import contains a template by s-hertel · Pull Request #85599 · ansible/ansible · GitHub. If you’re able to verify it fixes the issue for you, I’d appreciate any feedback.

Does

  ansible.builtin.import_tasks: ./_fetch_uri.yml

work?

Following is the task:

- name: Fetching power state of iDRAC
  ansible.builtin.import_tasks: _fetch_uri.yml
  vars:
    uri: "/redfish/v1/Chassis/System.Embedded.1?$select=PowerState"
  until: idrac_output.json.PowerState == "Off"
  retries: 10
  delay: 30

Unrelated to your question but just FYI using until on import_tasks is not supported and is simply ignored.

2 Likes