# How to configure playbook serial value by group var from inventory file?

**URL:** <https://forum.ansible.com/t/how-to-configure-playbook-serial-value-by-group-var-from-inventory-file/26695>\
**Category:** Ansible Project\
**Created:** [February 9, 2018, 9:35am UTC](https://forum.ansible.com/t/how-to-configure-playbook-serial-value-by-group-var-from-inventory-file/26695 "2018-02-09T09:35:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bing\_Hsueh](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bing\_Hsueh](https://forum.ansible.com/u/Bing_Hsueh)\
**Post date:** [February 9, 2018, 9:35am UTC](https://forum.ansible.com/t/how-to-configure-playbook-serial-value-by-group-var-from-inventory-file/26695/1 "2018-02-09T09:35:08Z")

</div>

I’ve tried to setup a group var “batch\_deploy” in my inventory file and use it in playbook serial field.  
But always got failed with following message.  
Is there any concept I misunderstanding?

> > PLAYBOOK: playbook.yml \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
> 
> > 1 plays in playbook.yml
> 
> > ERROR! The field ‘serial’ has an invalid value, which includes an undefined variable. The error was: ‘batch\_deploy’ is undefined
> 
> > 
> 
> > The error appears to have been in ‘/vagrant/ansible/playbook.yml’: line 2, column 5, but may
> 
> > be elsewhere in the file depending on the exact syntax problem.
> 
> > 
> 
> > The offending line appears to be:
> 
> > 
> 
> > * * *
> 
> > - name: test rolling update by batch size
> 
> > ^ here
> 
> > 
> 
> > exception type: \<class ‘ansible.errors.AnsibleUndefinedVariable’\>
> 
> > exception: ‘batch\_deploy’ is undefined

inventory.yml

`

---

<div class="post-metadata">

**Author:** ![azaghal](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/azaghal/32/4743_2.png) [@azaghal](https://forum.ansible.com/u/azaghal)\
**Post date:** [February 9, 2018, 12:40pm UTC](https://forum.ansible.com/t/how-to-configure-playbook-serial-value-by-group-var-from-inventory-file/26695/2 "2018-02-09T12:40:43Z")

</div>

> \> ERROR! The field 'serial' has an invalid value, which includes an  
> \>\> undefined variable. The error was: 'batch\_deploy' is undefined

Ansible is complaining that you are referencing a variable  
"batch\_deploy", and that it is not defined anywhere.

> inventory.yml  
> ---  
> deployservers:  
> &nbsp;&nbsp;&nbsp;&nbsp;vars:  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deploy\_batch: 1

Here, the variable is called "deploy\_batch".

> playbook.yml  
> ---  
> &nbsp;&nbsp;- name: test rolling update by batch size  
> &nbsp;&nbsp;&nbsp;&nbsp;hosts: deployservers  
> &nbsp;&nbsp;&nbsp;&nbsp;serial: "{{ batch\_deploy }}"

Here, the variable is called "batch\_deploy". E.g. not the same as in  
the inventory file (swapped batch/deploy in the name).

Best regards

---

<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, 2018, 3:08pm UTC](https://forum.ansible.com/t/how-to-configure-playbook-serial-value-by-group-var-from-inventory-file/26695/3 "2018-02-09T15:08:08Z")

</div>

This is because serial is a play level keyword and must be the same  
for ALL hosts in play, so inventory data cannot be used to set it.

You cannot set 'batches' of hosts for all play if the batch size keeps  
changing per host.

---

<div class="post-metadata">

**Author:** ![Bing\_Hsueh](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bing\_Hsueh](https://forum.ansible.com/u/Bing_Hsueh)\
**Post date:** [February 9, 2018, 5:14pm UTC](https://forum.ansible.com/t/how-to-configure-playbook-serial-value-by-group-var-from-inventory-file/26695/4 "2018-02-09T17:14:10Z")

</div>

Thanks for the explaination.

Now I know the reason why I cannot set the value from inventory file.

And also thanks for branko to point out the inconsistence of variable names, I didn’t notice that. 😛

Brian Coca於 2018年2月9日星期五 UTC+8下午11時08分27秒寫道：

---

<div class="post-metadata">

**Author:** ![Deepesh\_Jakkal](https://avatars.discourse-cdn.com/v4/letter/d/49beb7/32.png) [@Deepesh\_Jakkal](https://forum.ansible.com/u/Deepesh_Jakkal)\
**Post date:** [April 20, 2018, 1:26pm UTC](https://forum.ansible.com/t/how-to-configure-playbook-serial-value-by-group-var-from-inventory-file/26695/5 "2018-04-20T13:26:14Z")

</div>

So Brain, how do we provide a serial value then? I also want to externalize it so that our operator can configure it.  
Currently the way it supports is using extra variables --extra-vars.

Thanks and Regards,  
Deepesh
