Solved

Use of condition with 'serial' in ansible

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

757 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now