# Problem has no attribute 'public\_ip when I execute a playbook AWS

**URL:** <https://forum.ansible.com/t/problem-has-no-attribute-public-ip-when-i-execute-a-playbook-aws/3192>\
**Category:** Get Help\
**Tags:** playbook, aws, collections\
**Created:** [January 7, 2024, 11:29pm UTC](https://forum.ansible.com/t/problem-has-no-attribute-public-ip-when-i-execute-a-playbook-aws/3192 "2024-01-07T23:29:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dedeboy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dedeboy/32/2062_2.png) [@dedeboy](https://forum.ansible.com/u/dedeboy)\
**Post date:** [January 7, 2024, 11:29pm UTC](https://forum.ansible.com/t/problem-has-no-attribute-public-ip-when-i-execute-a-playbook-aws/3192/1 "2024-01-07T23:29:56Z")

</div>

Hello guys,  
I am provisioning instances in AWS, however, when adding a snapshot to the “temp” inventory, this error appears below:

```auto
- name: Adding a temp inventory
  ansible.builtin.add_host:
      name: "{{ item.public_ip }}"
       groups: giropops-new
   with_items: "{{ ec2.instances }}"

```

**fatal: [localhost]: FAILED! =\> {“msg”: "The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘public\_ip’. ‘dict object’ has no attribute ‘public\_ip’**

I’ve already searched the internet and read the Ansible manual, but so far I haven’t found any solution to this problem.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![akira6592](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/akira6592/32/222_2.png) [@akira6592](https://forum.ansible.com/u/akira6592)\
**Post date:** [January 8, 2024, 2:32am UTC](https://forum.ansible.com/t/problem-has-no-attribute-public-ip-when-i-execute-a-playbook-aws/3192/2 "2024-01-08T02:32:33Z")

</div>

Hello @dedeboy

What’s values does `ec2.instances` include?  
Could you try to check the debug module to see if the `public_ip` are included in `ec2.instances` list items?

FYI, for provisioned instances, another approach is to use [dynamic inventory](https://docs.ansible.com/ansible/latest/collections/amazon/aws/docsite/aws_ec2_guide.html) instead of `add_host` module.

---

<div class="post-metadata">

**Author:** ![shertel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/shertel/32/1241_2.png) [@shertel](https://forum.ansible.com/u/shertel)\
**Post date:** [January 8, 2024, 12:19pm UTC](https://forum.ansible.com/t/problem-has-no-attribute-public-ip-when-i-execute-a-playbook-aws/3192/3 "2024-01-08T12:19:00Z")

</div>

In addition to a [`debug`](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html) task to see what keys are available, modules should document the return structure (assuming you’re registering the `ec2` variable). If you’re using the `ec2_instance` module, for example the variable is documented here as [public\_ip\_address](https://docs.ansible.com/ansible/latest/collections/amazon/aws/ec2_instance_module.html#return-instances/public_ip_address), not `public_ip`.

---

<div class="post-metadata">

**Author:** ![dedeboy](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dedeboy/32/2062_2.png) [@dedeboy](https://forum.ansible.com/u/dedeboy)\
**Post date:** [January 10, 2024, 10:54pm UTC](https://forum.ansible.com/t/problem-has-no-attribute-public-ip-when-i-execute-a-playbook-aws/3192/4 "2024-01-10T22:54:46Z")

</div>

Hello guys,  
Sorry for delay in write post. First all I want to thank you, @shertel and @akira6592 to me help about this issue.  
I got solved it 🙂 I noticed that when I went to provisioning my AWS instance I forgot mentioned assign an IP public for it, then when I was running my playbook in that part “add\_host” the IP address couldn’t find the IP to store the information, then error message occurred.

@shertel thank you, I fixed up it.

Thank in advance.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [February 9, 2024, 10:55pm UTC](https://forum.ansible.com/t/problem-has-no-attribute-public-ip-when-i-execute-a-playbook-aws/3192/5 "2024-02-09T22:55:00Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
