5

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.

Ciprian Stoica
  • 2,309
  • 5
  • 22
  • 36
  • 8
    You are mixing Ansible version and their syntaxes. If you are in a version `>= 2.10` the module fully qualified name applies, otherwise, not. So your task should simply be [`ec2_instance_info`](https://docs.ansible.com/ansible/2.9/modules/ec2_instance_info_module.html#examples) and not [`aws.community.ec2_instance_info`](https://docs.ansible.com/ansible/2.10/collections/community/aws/ec2_instance_info_module.html#examples) – β.εηοιτ.βε Oct 19 '21 at 16:54
  • @β.εηοιτ.βε thank you for the suggestion. I will try to upgrade ansible to version 2.10. What is strange is that the plugins behaviour is not consistent though I use version 2.9 on all the machines. For example I call `community.aws.route53` and `ec2_instance_info` in the same playbook. On one machine `route53` works only with the suffix and `ec2_instance_info` only without it. On other machines I used to always call them with the suffix and I never had issues. I hope that after upgrading to 2.10 we get rid of these issues. – Ciprian Stoica Oct 20 '21 at 08:13
  • The 2.0.0 version of that collection does not seem to have ec2_instance_info any more, for reasons I do not know. If you want something that is compatible with the current documentation use version "1.5.0" instead, which is what I did. – Oliver Weise Nov 02 '21 at 11:59
  • @β.εηοιτ.βε I managed to upgrade ansible to version 4.7.0 on all the machines and indeed I can access the module with the fully qualified name on all of them. If you post your comment as an answer I'll gladly mark it as the correct answer. :-) Thanks again. – Ciprian Stoica Nov 02 '21 at 12:42
  • 1
    @OliverWeise version 2.0.0 works for me without any issues now that I upgraded ansible to 4.7.0. – Ciprian Stoica Nov 02 '21 at 12:43

1 Answers1

-1

Install on that machine running this:

ansible-galaxy collection install community.aws
ansible-galaxy collection install amazon.aws:==3.3.1 --force
toyota Supra
  • 3,181
  • 4
  • 15
  • 19