0

I am working on a project using ansible AWX. In this project I have a check to see if all my microk8s pods are in the state running. Before I installed AWX I was testing all my plays on my linux vm. The following play worked fine on my linux vm but does not seem to work in ansible awx.

- name: Wait for pods to become running
  hosts: host_company_01
  tasks:
    - name: wait for pod status
      shell: kubectl get pods -o json
      register: kubectl_get_pods
      until: kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == ["Running"]
      timeout: 600

AWX gives me the following respons

[WARNING]: an unexpected error occurred during Jinja2 environment setup: unable
to locate collection community.general
fatal: [host_company_01]: FAILED! => {"msg": "The conditional check 'kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == [\"Running\"]' failed. The error was: template error while templating string: unable to locate collection community.general. String: {% if kubectl_get_pods.stdout|from_json|json_query('items[*].status.phase')|unique == [\"Running\"] %} True {% else %} False {% endif %}"}

I have looked at the error message and tried different possible solutions but without any effect.

First thing I tried was looking for the community.general collections in the ansible galaxy collection list. After I saw that it was found I tried downloading it once again, but this time with sudo. The collection was installed. After running my workflow template, the error message popped up again.

Second thing was trying to use different Execution environments, I thought that this was not going to make any difference but tried it anyways since someone online fixed a similar issue by changed EE.

Last thing I tried was trying to find a way around this play by building a new play with different commands. Sadly I was not able to build an other play that did what the original one did.

Since I can not build a play that fits my needs I came back at the error message to try and fix it.

Lars
  • 1
  • 1
  • You probably installed `ansible-core` via pip and not `ansible`. If that's the case, you need to install the collection, as described in the documentation: https://galaxy.ansible.com/community/general – β.εηοιτ.βε Nov 22 '22 at 09:30
  • Hi @β.εηοιτ.βε you are right, anisble-core in installed not ansible. But I am sure that the collection is installed. `Starting galaxy collection install process Nothing to do. All requested collections are already installed.`. When I search for the installed collections community-general is available. – Lars Nov 22 '22 at 09:39
  • Are you sure they are installed in a location your ansible-playbook binary consider them? Show us the first lines of `ansible-galaxy collection list` and what `ansible --version` gives you. Also ensure that ansible run in the command line is the same as the one AWX uses (e.g. you don't have a virtual env messing somewhere). – β.εηοιτ.βε Nov 22 '22 at 09:46
  • ansible-galaxy collection command `# /home/vmuser/.ansible/collections/ansible_collections ansible.netcommon 4.1.0 ansible.utils 2.7.0 community.general 6.0.1 kubernetes.core 2.3.2 ` ansible --version `ansible [core 2.13.5] config file = /etc/ansible/ansible.cfg ansible collection location = /home/vmuser/.ansible/collections:/usr/share/ansible/collections executable location = /home/vmuser/.local/bin/ansible python version = 3.10.6 (main, Nov 2 2022, 18:53:38) [GCC 11.3.0] jinja version = 3.0.3 libyaml = True` – Lars Nov 22 '22 at 09:53
  • I just changed the collection path to `location = /home/vmuser/.ansible/collections/ansible_collections:/usr/share/ansible/collections/ansible but this made no difference`. But this did not change anything – Lars Nov 22 '22 at 10:33
  • Could it be that since my awx is running from a microk8s container, the pod can't access my storage and he is looking for these collection in the mapped volumes? – Lars Nov 22 '22 at 10:48

0 Answers0