On 07.11.2019 07:24, Mohtashim S wrote:
> Incase a variable "outputmsg" has not been defined and assigned a value
> using set_fact in the playbook I wish to assign a string value to the
> variable.
>
> Howver, if outputmsg is defined and is assigned some value which is the
> case, i expect the below 'GET THE STATUS' message to be skipped.
>
> Below is what I do:
>
> - name: Set output message incase the process is already not
> RUNNING
> tags: stop_tomcat
> set_fact:
> outputmsg: "{{ 'ALREADY in SHUTDOWN state' if
> running_processes.stdout == '' else 'STOPPING NOW' }}"
>
>
> - name: Status of Running process
> tags: always
> set_fact:
> outputmsg: "{{ 'GET THE STATUS' if outputmsg is undefined }}"
>
>
> I was expecting the above code to assign 'GETTING THE STATUS' incase
You got a soulution from vlado, but the reason this doesn't work is
because there is no test called undefined, you only have defined and can
use "not" to get you desire behavior.
"{{ 'GET THE STATUS' if outputmsg is not defined }}"
--
Kai Stian Olstad