Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Use of condition with 'serial' in ansible

Posted on 2016-08-31
2
Medium Priority
?
200 Views
Last Modified: 2016-09-12
I'm looking to use a condition for use with serial option in ansible.

The current line is :
serial: '{{ serial_var | default("0") }}'

I would like something like the following but I'm unsure if of syntax:
serial: '{{ serial_var | "0" if action == "deploy" else "1" if action == "upgrade" }}'

The following works but I would prefer not to have both in my file.

- hosts: [mysqlcluster-ndb, mysqlcluster-api]
  serial: '{{ serial_var | default("0") }}'
  roles:
    - { role: mysqlcluster, tags: mysqlcluster, when: enable_mysqlcluster | bool }

- hosts: [mysqlcluster-ndb, mysqlcluster-api]
  serial: 1
  roles:
    - { role: mysqlcluster, tags: mysqlcluster, when: enable_mysqlcluster | bool and action | default('upgrade') }
0
Comment
Question by:mickt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 

Accepted Solution

by:
mickt earned 0 total points
ID: 41791038
Seems as if dropping the serial var is all that is required.

serial: '{{ "0" if action == "deploy" else "1" if action == "upgrade" }}'

values can be changed to % if preferable, e.g. "1" -> "30%"
0
 

Author Comment

by:mickt
ID: 41794204
Error in above, should be:

serial: '{{ "0" if action == "deploy" else "1" }}'
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question