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

45 views
Skip to first unread message

Bing Hsueh

unread,
Feb 9, 2018, 4:35:08 AM2/9/18
to Ansible Project
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
---
deployservers:
    vars:
         deploy_batch: 1
        
    hosts:
         app-server-1:
         app-server-2:
         app-server-3:
...


playbook.yml
---
  - name: test rolling update by batch size
    hosts: deployservers
    serial: "{{ batch_deploy }}"
    roles:
        - deploy
...



Branko Majic

unread,
Feb 9, 2018, 7:41:09 AM2/9/18
to ansible...@googlegroups.com
On Fri, 9 Feb 2018 01:35:08 -0800 (PST)
Bing Hsueh <bing.t...@gmail.com> wrote:

> > 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:
> vars:
> deploy_batch: 1

Here, the variable is called "deploy_batch".

> playbook.yml
> ---
> - name: test rolling update by batch size
> hosts: deployservers
> 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

--
Branko Majic
XMPP: bra...@majic.rs
Please use only Free formats when sending attachments to me.

Бранко Мајић
XMPP: bra...@majic.rs
Молим вас да додатке шаљете искључиво у слободним форматима.

Brian Coca

unread,
Feb 9, 2018, 10:08:27 AM2/9/18
to Ansible Project
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.




--
----------
Brian Coca

Bing Hsueh

unread,
Feb 9, 2018, 12:14:10 PM2/9/18
to Ansible Project
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. :p

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

Deepesh Jakkal

unread,
Apr 20, 2018, 9:26:14 AM4/20/18
to Ansible Project
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
Reply all
Reply to author
Forward
0 new messages