When I run this simple Ansible playbook:
- name: EC2 Test Example
hosts: localhost
connection: local
gather_facts: False
tasks:
- name: EC2 Instan
The root cause of your problem is the -i localhost,
hack. You don't need to use it anymore in Ansible.
You can just run:
ansible-playbook playbook.yml
And with connection: local
in the play Ansible will use the Python executable set by venv.
When you use the -i localhost,
hack, Ansible calls its default /usr/bin/python
.
In this case you still can add the ansible_python_interpreter
parameter to tell Ansible to use this specific environment:
ansible-playbook -i localhost, playbook.yml --extra-vars "ansible_python_interpreter=/Users/admin/temp/ansec2/venv/bin/python"
But I think you should avoid it and use the first method.