Solved

Use of condition with 'serial' in ansible

Posted on 2016-08-31
2
87 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
while loop over for loop 7 116
Message not shown 5 85
Bartender label printing - switch on and off graphics 3 74
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

749 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