Solved

Use of condition with 'serial' in ansible

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 67
sameEnds challenge 3 159
either24  challenge 19 97
EvenOdd challenge 10 108
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 …
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…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

773 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