# Ansible loop issue

**URL:** <https://forum.ansible.com/t/ansible-loop-issue/38849>\
**Category:** Ansible Project\
**Tags:** vmware\
**Created:** [August 16, 2024, 5:52pm UTC](https://forum.ansible.com/t/ansible-loop-issue/38849 "2024-08-16T17:52:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Bachmeyer](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@Chris\_Bachmeyer](https://forum.ansible.com/u/Chris_Bachmeyer)\
**Post date:** [August 16, 2024, 5:52pm UTC](https://forum.ansible.com/t/ansible-loop-issue/38849/1 "2024-08-16T17:52:45Z")

</div>

Hi, Community,

I am passing in a list, ‘vmware\_hosts’, to the loop in the following task in order to substitute values for the name: and hostname: parameters. I have found only the sub is being made for name: but not for hostname:.

- name: Set powerstate of a virtual machine to poweron  
community.vmware.vmware\_guest:  
hostname: “{{ vc\_host\_id }}”  
username: “{{ username }}”  
password: “{{ survey\_password }}”  
name: “{{ item }}”  
customization:  
existing\_vm: true  
dns\_servers:
- “{{ dns\_ns1 }}”
- “{{ dns\_ns2 }}”  
hostname: “{{ item }}”  
state: poweredon  
wait\_for\_ip\_address: true  
loop: “{{ vmware\_hosts }}”  
register: vm\_state  
delegate\_to: localhost

For each iteration of the loop, i.e. a different host, I need these two parameters to hold the same value.

What am I missing here?

Thanks!

---

<div class="post-metadata">

**Author:** ![utoddl](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/utoddl/32/249_2.png) [@utoddl](https://forum.ansible.com/u/utoddl)\
**Post date:** [August 16, 2024, 6:16pm UTC](https://forum.ansible.com/t/ansible-loop-issue/38849/2 "2024-08-16T18:16:20Z")

</div>

I’m inclined to believe someone is confused by the two `hostname:` parameters, and would need to see some job log evidence supporting the claim that “the sub[stitution] is being made for `name:` but not for `hostname:`.” In any case, something from the job log would/should be informative.

I’ve found in situations like this it’s helpful to change to module to `ansible.builtin.debug:` immediately followed by `msg: |`. You’d then need to play with indentation a little to make it informative.

---

<div class="post-metadata">

**Author:** ![Chris\_Bachmeyer](https://avatars.discourse-cdn.com/v4/letter/c/3e96dc/32.png) [@Chris\_Bachmeyer](https://forum.ansible.com/u/Chris_Bachmeyer)\
**Post date:** [August 16, 2024, 9:27pm UTC](https://forum.ansible.com/t/ansible-loop-issue/38849/3 "2024-08-16T21:27:48Z")

</div>

Thanks, Todd.

According the docs, the name: param is for the virtual machine and hostname: under customization: is for setting the hostname. I was able to register the stdout of the task, capturing it  
to a variable. The substitutions are being made.

“instance”: {  
“module\_hw”: true,  
“hw\_name”: “rheltest0816d”,  
“hw\_power\_status”: “poweredOn”,

-and-

“customization”: {  
“existing\_vm”: true,  
“dns\_servers”: [  
“redacted”,  
“redacted”  
],  
“domain”: “”,  
“hostname”: “rheltest0816d”,

The hostname is not being updated on the vm though and that’s causing a glitch downstream in the next job template in the workflow.  
I’m not sure if I should move the state: param near the beginning of the task.
