错误!无法解析模块/操作"community.aws.ec2_instance_info"。这通常表示拼写错误、缺少集合或模块路径不正确



我有一些安装了ansible的Ubuntu 18.04机器。当在所有这些服务器上运行ansible --version时,我得到以下输出:

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]

顺便说一下,configured module search path中定义的路径不存在。

我安装了社区。所有机器上的Aws集合:ansible-galaxy collection install community.aws

我运行了一个简单的剧本从一些AWS EC2实例收集数据:

- 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}}"

在所有机器上一切正常,除了一个,我得到以下错误:

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

我运行了sudo find / -name "ec2_instance_info.py"来查看可能安装该文件的位置。在所有机器上,我得到完全相同的输出:

/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

我甚至强行重新安装了那台机器,运行以下命令:

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

我得到了这样的输出:

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'

但这并没有改变什么。

我还在以前一切正常的机器上运行了强制重新安装。我也设法打破了它。现在我有两台机器出现了这个问题。

一个解决方案是直接调用ec2_instance_info在我的剧本,而不是community.aws.ec2_instance_info。这是有效的,但我不知道为什么。无论如何,我不喜欢这个解决方案,因为一些可见的法律插件工作没有社区。Aws有前缀,其他的没有。除此之外,当我调用这样一个没有前缀的插件时,VS Code会给我很多警告。

你知道怎么解决这个问题吗?我想在我的剧本中调用community.aws.ec2_instance_info,而不会在任何机器上出现任何问题。

在机器上安装:

ansible-galaxy collection install community.aws
ansible-galaxy collection install amazon.aws:==3.3.1 --force

最新更新