Ansible ec2_instance_facts complaining boto3 is not installed (but it is)

amazon-web-servicesansible

Trying to retrieve AWS metadata with Ansible with a simply playbook like:

    ---
    - hosts: tag_mytagname_mytagvalue
      tasks:
        - ec2_instance_facts
        - ping

I get an error about boto3 being missing (although already installed)

TASK [ec2_instance_facts]
********************************************************************************************************** fatal: [ip-10-186-27-189.ec2.internal]: FAILED! => {"changed": false,
"msg": "boto3 required for this module"}

Best Answer

This turned out to be because Ansible is attempting to retrieve EC2 facts on the remote host (because that's what I told it to, d'Oh!)

Need to retrieve the facts using the localhost:

---
- hosts: localhost
  tasks:
    - ec2_instance_facts:

Credit to this reddit for the solution (but more useful to have it here on SF): https://www.reddit.com/r/ansible/comments/8p4l9f/awsec2_group_facts_error_boto3_required_for_this/