using module ec2_instance_info get private ip

19 views
Skip to first unread message

SysAdmin EM

unread,
May 3, 2022, 12:52:55 PM5/3/22
to ansible...@googlegroups.com

Hi,

I’m trying to get the private ip of an instance by filtering by the tag name but I get the following error:

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'private_ip_address'\n\nThe error appears to be in '/etc/ansible/loyalty/tasks/create_ec2.yaml': line 59, column 7, but may\nbe elsewhere in the file depe nding on the exact syntax problem.\n\nThe offending line appears to be:\n\n      register: ec2_metadata\n    - name: Muestro la IP publica de la ins tancia creada\n      ^ here\n"}   

Here my yaml:
- name: instances info
ec2_instance_info:
region: us-west-2
filters:
"tag:Name": myserver
register: ec2_metadata
- name: show info
debug:
msg: "{{ ec2_metadata.instances[0].private_ip_address }}"

What am I doing wrong?

Regards,


Reply all
Reply to author
Forward
0 new messages