# Serial in playbook - missing variable

**URL:** <https://forum.ansible.com/t/serial-in-playbook-missing-variable/31893>\
**Category:** Ansible Project\
**Created:** [January 2, 2020, 10:57pm UTC](https://forum.ansible.com/t/serial-in-playbook-missing-variable/31893 "2020-01-02T22:57:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dawid\_D](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Dawid\_D](https://forum.ansible.com/u/Dawid_D)\
**Post date:** [January 2, 2020, 10:57pm UTC](https://forum.ansible.com/t/serial-in-playbook-missing-variable/31893/1 "2020-01-02T22:57:43Z")

</div>

Hello Community,

I have a question related with my ansible playbook. Let me describe an issue:

I use hostvars in template like:

{% for host in groups[‘elasticsearch’] %}

- {{ hostvars[host].ansible\_default\_ipv4.address }}  
{% endfor %}

all working fine, but wen I use serial option in my playbook:

- name: Upgrade Elasticsearch  
hosts: elasticsearch

gather\_facts: yes

serial: 1  
tasks:

- name: Check Elasticsearch cluster state - Need to be green before upgrade  
[…]
- import\_role:  
name: u\_elasticsearch

I receiving error:

TASK [u\_elasticsearch : Elasticsearch template config] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* failed: [elk1] (item=elasticsearch.yml) =\> {“ansible\_loop\_var”: “item”, “changed”: false, “item”: “elasticsearch.yml”,  
“msg”: “AnsibleUndefinedVariable: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘ansible\_all\_ipv4\_addresses’”}

I understood that this is because of missing all facts, is it any possibility to force gather all facts and perform serial …

I will be really happy for Your help

---

<div class="post-metadata">

**Author:** ![Dawid\_D](https://avatars.discourse-cdn.com/v4/letter/d/e8c25b/32.png) [@Dawid\_D](https://forum.ansible.com/u/Dawid_D)\
**Post date:** [January 2, 2020, 11:07pm UTC](https://forum.ansible.com/t/serial-in-playbook-missing-variable/31893/2 "2020-01-02T23:07:07Z")

</div>

Small update, I know about:

`

- name: gather facts from elasticsearch servers

setup:

delegate\_to: “{{ item }}”

delegate\_facts: True

loop: “{{ groups[‘elasticsearch’] }}”

`

Is there any more elegant option ? Maybe some parameter which I didn’t know ?

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [January 3, 2020, 8:29am UTC](https://forum.ansible.com/t/serial-in-playbook-missing-variable/31893/3 "2020-01-03T08:29:43Z")

</div>

If they are more elegant or not I leave that up to you to deside.

In your playbook you could have to plays, where the first one only gather facts

&nbsp;&nbsp;&nbsp;- hosts: elasticsearch  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gather\_facts: yes

&nbsp;&nbsp;&nbsp;- hosts: elasticsearch  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gather\_facts: no  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;serial: 1

An other alternative if you only need a few tasks to run in serial is to use the new throttle on the task/tasks itself

[https://docs.ansible.com/ansible/latest/user\_guide/playbooks\_strategies.html#using-keywords-to-control-execution](https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html#using-keywords-to-control-execution)
