ansible / ansible-lint

ansible-lint checks playbooks for practices and behavior that could potentially be improved and can fix some of the most common ones for you
https://ansible.readthedocs.io/projects/lint/
GNU General Public License v3.0
3.5k stars 664 forks source link

"Relative resource paths not supported" warning during Jinja2 environment setup #1238

Closed tgdfool2 closed 3 years ago

tgdfool2 commented 3 years ago
Summary

While trying to ansible-lint one of our Playbooks, we are receiving a warning regarding "relative resource paths not supported during Jinja2 environment setup"

Issue Type
Ansible and Ansible Lint details
root@d8bcd70452a4:/work# ansible --version
ansible 2.10.4
  config file = /work/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]

root@d8bcd70452a4:/work# ansible-lint --version
ansible-lint 4.3.7
OS / ENVIRONMENT
root@d8bcd70452a4:/work# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

root@d8bcd70452a4:/work# uname -a
Linux d8bcd70452a4 4.19.104-microsoft-standard #1 SMP Wed Feb 19 06:37:35 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
STEPS TO REPRODUCE
  1. By using the following task as part of our Playbook:

        - name: Set Internal Load Balancer Address
          set_fact:
            ilb_ip_address: "{{ k8s_subnet.subnets[0].address_prefix_cidr | ansible.netcommon.ipaddr('address') }}"
  2. ansible-lint outputs the following warning:

    root@d8bcd70452a4:/work# ansible-lint -v sensu_nginx_ingress.yml
    [WARNING]: an unexpected error occurred during Jinja2 environment setup: relative resource paths not supported
  3. By removing the second part of the expression, ansible-lint does not complain anymore:

        - name: Set Internal Load Balancer Address
          set_fact:
            ilb_ip_address: "{{ k8s_subnet.subnets[0].address_prefix_cidr }}"

But the initial code is working as expected, so we don't really understand the meaning of this warning.

Could you please give us some hints?

Thanks in advance!

tadeboro commented 3 years ago

Https://github.com/ansible-community/ansible-lint/pull/1170 should fix this issue. But just to be sure, can you describe a bit more how and where did you install ansible.netcommon collection?

tgdfool2 commented 3 years ago

Thanks for your feedback @tadeboro. Here is how and where ansible.netcommon has been installed:

root@d8bcd70452a4:/work# cat collections/requirements.yml
---
collections:
  - name: ansible.netcommon

root@d8bcd70452a4:/work# ansible-galaxy collection install -r collections/requirements.yml -p collections/

root@d8bcd70452a4:/work# find collections/ansible_collections/ansible/netcommon/ | head -3
collections/ansible_collections/ansible/netcommon/
collections/ansible_collections/ansible/netcommon/.gitignore
collections/ansible_collections/ansible/netcommon/meta

Basically, our collections are "locally installed" under the Playbook's collection path.

I'll try to use the pre-release of ansible-lint in our CI infrastructure to confirm that the issue has been fixed in the meantime.

tgdfool2 commented 3 years ago

I did a short test with the v5.0.0a0 pre-release and I can confirm that everything looks fine.