Issue
I set up a new Ansible project, in which I want to connect to my EC2 machines and run a few commands.
I added my inventory files, and when I test out a simple Ansible command, everything works fine and I get a response.
ansible all -m shell -a 'uptime'
or ansible all -m ping
works well and returns the expected output.
However, when I'm trying to run a simple playbook that uses the built-in shell module, it fails.
Ansible playbook command: ansible-playbook -vvv playbooks/my_playbook.yaml
Playbook file:
---
- hosts: all
become: yes
gather_facts: yes
tasks:
- name: Gather EC2 facts
action: ec2_facts
- hosts: all
become: yes
tasks:
- name: my task
shell: uptime
Gathering EC2 facts works well, but the second part of running a shell command fails with the following exception:
<1.2.3.4> Failed to connect to the host via ssh:
fatal: [1.2.3.4]: FAILED! => {
"changed": false
}
MSG:
This module has been removed. The module documentation for Ansible-2.6 may contain hints for porting
I can't figure out why I'm getting this exception, as the shell module was never deprecated. I also don't use Ansible-2.6, I installed Ansible through pip, versions:
ansible==2.9.27
ansible-core==2.15.8
I tried to change to the command module, which resulted in the same exception, so I suspect it has to do something with my local environment and not with the shell module itself.
Any help would be highly appreciated.
Solution
You are calling ec2_facts
as a module, which has been deprecated and then removed in Ansible 2.7 (they failed to list it in the documentation though). Try to use ec2_metadata_facts
instead.
Answered By - Alexander Pletnev Answer Checked By - Mary Flores (WPSolving Volunteer)