I've been working on a play to create a virtual server and am doing it by asking the user some questions to gather the configuration requirements.
I'd like to run some pre-checks to show that certain virtual server properties exist, I've been able to work out all the properties with the exception of the profile.
When you run "list ltm profile" you need to specify the protocol, then the profile name, for example, "list ltm profile tcp tcp". Checking one LTM profile is fine, but the difficulty I'm having is when you need to check multiple profiles.
Is there a way I could loop my question and pass the users input into the check? Let's say the user wants to check the below profiles:
list ltm profile http http
list ltm profile tcp tcp
Here is the question asked:
- name: "vs_profile_type"
prompt: "enter the profile(s) to run your pre-checks against"
private: no
And here is what I have for the pre-check portion of the play:
- name: Pre-check
bigip_command:
server: "{{ inventory_hostname }}"
user: "{{ remote_username }}"
password: "{{ remote_passwd }}"
commands:
- "tmsh list sys global-settings hostname"
- "tmsh show sys failover"
- "tmsh show cm sync-status"
- "tmsh list ltm virtual {{ vs_name }}"
- "tmsh list ltm profile {{ vs_profile_type }}"
- "tmsh list ltm pool {{ vs_pool }}"
- "tmsh list ltm rule {{ vs_rule }}"
warn: no
validate_certs: no
delegate_to: localhost
when: "'active' in Active_LTM['stdout'][0]"
register: Active_LTM_Pre_Checks
I was also looking at accounting for the fact that the user may not want a profile, so if they press enter, I'd need the "list ltm profile xxx xxx" check skipped. In another post I had some help doing this, but in re-working the syntax for this instance, I couldn't seem to get it working; any ideas what might be off with the below syntax?
"tmsh list ltm profile {{ '{' + vs_profile_type + '}' if vs_profile_type else '' }} {{ '{' + vs_profile + '}' if vs_profile else '' }}"
We got this working doing it this way.
Question asked to the user:
We wound up running this check for the profile in a separate task:
Here is the play up to that check/task: