I can't make this simple conditional to work.
I use pause in a role for user confirmation and I register the input to variable.
I use this variable in the next 2 tasks:
- one to run when input is
y - the other when is
n
But I can't make the condition to work based on the user input.
Below is the tasks/main.yml
# tasks file for Update-AdvFirewall-to-V1.6
- name: Get Note
routeros_command:
commands: /system note print
register: output
- name: Get AdvFirewall Version
set_fact:
installed: "{{ item | replace('- AdvFirewall=V', '') | trim }}"
when: "'AdvFirewall=V' in item"
loop: "{{ output.stdout_lines[0] }}"
- name: Confirm if not Installed
pause:
prompt: "AdvFirewall is not installed. Do you want to install (y/n)"
when: installed is undefined
register: confirm_new_install
- name: Install AdvFirewall if not installed
routeros_command:
commands:
- system note set note="Installed ADVfirewall"
when: confirm_new_install == "y"
- meta: end_play
when: confirm_new_install is defined or installed is undefined
- name: Upgrade AdvFirewall if needed
routeros_command:
commands:
- system note set note="Time to upgrade"
when: installed == "1.5"
- name: Send Email if AdvFirewall is older than required
routeros_command:
commands:
- "/tool e-mail send to=\"[email protected]\" subject=\"AdvFirewall Upgrade | Installed Version doesn`t meet requirements for upgrade on $[/system identity get name]\" body=\"$[/system identity get name] has AdvFirewall V{{ installed }}. Required Version is V{{ required }}\""
when: installed < "1.5"
Edit: After all it works with some changes i figured out with your help.
- name: Install AdvFirewall if not installed
routeros_command:
commands:
- system note set note="Installed ADVfirewall"
when: "confirm_new_install.user_input | default('X') == 'y'"
- meta: end_play
when: "confirm_new_install.user_input | default('X') != 'X'"
Thank you very much!