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
Solved

Use of condition with 'serial' in ansible

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

856 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