Ansible: Can't set variable for sequential exe

2019-07-31 17:15发布

I'm trying to build a playbook with rolling update use case (Sequential Execution) with the serial element. Since I have to use the serial value in multiple places in the playbook, I wanted to use it as a variable which can be used to define somewhere as a group variable.

Inventory file

[all]
webserver1  ansible_host=10.1.1.1 ansible_user=root
webserver2  ansible_host=10.1.1.2 ansible_user=root
webserver3  ansible_host=10.1.1.3 ansible_user=root
dbserver1  ansible_host=10.1.2.1 ansible_user=root

[webserver]
webserver1
webserver2
webserver3

[dbserver]
dbserver1

[app-stack:children]
webservers
dbservers

[app-stack:vars]
app_stack_serial_value=1

Playbook

- hosts: app-stack
  serial: "{{ app_stack_serial_value }}"
  tasks:
   - name: debug
     debug:
       msg: "Ansible Host - {{ ansible_host }}"

Error

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

This will work if I specify the value in the serial field like serial: 1. But I wanted to use this value as a variable. Any Idea ??

Ansible Version: ansible 2.7.10

python version = 3.7.2 (default, Jan 13 2019, 12:50:01) [Clang 10.0.0 (clang-1000.11.45.5)]

0条回答
登录 后发表回答