ERROR! couldn't resolve module/action 'community.aws.ec2_instance_info'.This often indicates a misspelling,missing collection,or incorrect module path

Viewed 4303

I have a few Ubuntu 18.04 machines with ansible installed. When running ansible --version on all of them, I get the following output:

ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.17 (default, Feb 27 2021, 15:10:58) [GCC 7.5.0]

By the way, the paths defined at configured module search path don't exist.

I installed community.aws collection on all machines: ansible-galaxy collection install community.aws

I ran a simple playbook to collect data from some AWS EC2 instance:

- name: test playbook
  hosts: localhost
  tasks:

  - name: "Set vars"
    set_fact:
      ec2_instance_name: "SomeName"

  - name: "Gather EC2 instance info: {{ ec2_instance_name }}."
    community.aws.ec2_instance_info:
      aws_access_key: "{{ lookup('env', 'AWS_ACCESS_KEY') }}"
      aws_secret_key: "{{ lookup('env', 'AWS_SECRET_KEY') }}"
      region: "{{ lookup('env', 'AWS_REGION') }}"
      filters:
        "tag:Name": "{{ ec2_instance_name }}"
    register: ec2_instance_info_ret

  - name: "Show data"
    debug:
      msg: "{{ec2_instance_info_ret}}"

Everything works fine on all the machines except one, where I get the following error:

ERROR! couldn't resolve module/action 'community.aws.ec2_instance_info'. This often indicates a misspelling, missing collection, or incorrect module path.

I ran a sudo find / -name "ec2_instance_info.py" to see where that file might be installed. On all the machines I got exactly the same output:

/usr/lib/python2.7/dist-packages/ansible/modules/cloud/amazon/ec2_instance_info.py
/root/.ansible/collections/ansible_collections/amazon/aws/plugins/modules/ec2_instance_info.py
/home/ubuntu/.ansible/collections/ansible_collections/community/aws/plugins/modules/ec2_instance_info.py

I even forced a reinstall on that machine running this:

ansible-galaxy collection install community.aws --force-with-deps

I got this output:

Installing 'community.aws:2.0.0' to '/home/ubuntu/.ansible/collections/ansible_collections/community/aws'
Installing 'amazon.aws:2.0.0' to '/home/ubuntu/.ansible/collections/ansible_collections/amazon/aws'

But this did not change anything.

I also ran the force reinstall on a machine where previously everything worked fine. And I managed to break it too. Now I have two machines where the issue is reproducing.

One solution is to call directly ec2_instance_info in my playbook instead of community.aws.ec2_instance_info. This works but I don't know why. Anyway, I don't like this solution because some ansible aws plugins work without the community.aws prefix and others don't. Besides that VS Code gives me a lot of warnings when I call such a plugin without the prefix.

Do you have any idea how to fix this? I would like to call community.aws.ec2_instance_info in my playbook without getting any issues on any machine.

0 Answers
Related