Help using two options for a value for a template

9 views
Skip to first unread message

gabriel...@gmail.com

unread,
Oct 16, 2018, 3:03:51 PM10/16/18
to Ansible Project
Hi guys,

Here is why im triying to do:

im generating passwords and registering the output in a variable like this

- name: Generate Server Password
      raw: Secret=$(az keyvault secret show --name AdminPassword --vault-name "{{ keyvault }}" --query value --output tsv);if [ -z $Secret ];then echo $(</dev/urandom tr -dc 'A-Za-z0-9#()*+=>?~' | head -c 32 );else echo "$Secret"  ;fi
      register: AdminPassword



after i have that AdminPassword variable inside a template of azure_rm_deployment


AdminPassword:
            value: "{{ LogRWebAdminPassword.stdout_lines[0] }}"



If the passwords generates it works ok. but if the password doesnt generate (cos sometimes we dont want to generate) it fails cos its waiting a value. I tried to use the operator default like this but it doues not work


AdminPassword:
            value: "{{ LogRWebAdminPassword.stdout_lines[0] | default(string) }}"



Anyone has some idea how can i give the AdminPassword value options if the 1st one fails?

Thanks a lot!


Reply all
Reply to author
Forward
0 new messages