Given the following input:
hosts = [{
"name": "serverA",
"os": "windows",
},{
"name": "serverB",
"os": "linux",
}]
I wish to do the following pseudocode in my orquesta workflow:
for host in hosts:
if host["os"] == "windows":
run_cmd_on_windows(host["name"])
elif host["os"] == "linux":
run_cmd_on_linux(host["name"])
However, I could not find a way to do an if
statement with Orquesta. I thought I could do it
with the when
directive, like so:
input:
- hosts
tasks:
determine_os:
with:
items: "{{ ctx('hosts') }}"
action: "core.noop"
next:
- when: "{{ item()['os'] == 'windows'}}"
publish: currentHostName="{{ item()['name'] }}"
do: run_cmd_on_windows
- when: "{{ item()['os'] == 'linux'}}"
publish: currentHostName="{{ item()['name'] }}"
do: run_cmd_on_linux
run_cmd_on_windows:
action: "core.winrm_ps_cmd"
input:
host: "{{ currentHostName }}"
cmd: "my-command --arg"
run_cmd_on_linux:
action: "core.remote_sudo"
input:
host: "{{ currentHostName }}"
cmd: "my-command --arg"
However, it seems that in the next
block, the item()
function returns None
,
making the comparison impossible.
Is it possible to do such an if
statement?