On 5/7/20 10:35 AM, דודו דודו wrote:
> i have a variable (domain_name) located on external YML file,
> I wish to run a task in case the variable is empty. From some reason, it is always skipping no matter if i have a
> value or not
>
You are doing a string test on an undefined variable, try (untested):
when: domain_name | default("") == ""
Regards
Racke
>
> *External Yaml*
>
>
> domain_name:
> ldap_server_hostname: 10.168.233.77 # Ip can be used as well
> ldap_port: 389
>
>
>
> *Playbook*
>
>
> - hosts: k8s_master
> become: true
> gather_facts: true
> vars_files: ./keycloak_configuration.yml
> tasks:
>
>
> - debug:
> msg: "{{domain_name}}"
>
> ### Copy realm for none LDAP Support ###
>
> - name: Copy realm LDAP Support
> copy:
> src: "{{ realm_src_path }}{{ realm_template_file_name }}"
> dest: "{{ realm_dest_path }}{{ realm_updated_file_name }}"
> when: domain_name == ""
>
>
> *result *
>
> TASK [debug]
> **************************************************************************************************************************************************************************************
> task path: /data/ansible/new2_keycloak/create-realm-secert.yml:18
> ok: [10.164.237.140] => {
> "msg": null
> }
> Read vars_file './keycloak_configuration.yml'
>
> TASK [Copy realm LDAP Support]
> *******************************************************************************************************************************************************************
> task path: /data/ansible/new2_keycloak/create-realm-secert.yml:23
> skipping: [10.164.237.140] => {
> "changed": false,
> "skip_reason": "Conditional result was False"
> }
> META: ran handlers
> META: ran handlers
>
>
> *result *- When updating domain_name with *test *value
>
>
> TASK [debug]
> **************************************************************************************************************************************************************************************
> task path: /data/ansible/new2_keycloak/create-realm-secert.yml:18
> ok: [10.164.237.140] => {
> "msg": "test"
> }
> Read vars_file './keycloak_configuration.yml'
>
> TASK [Copy realm LDAP Support]
> *******************************************************************************************************************************************************************
> task path: /data/ansible/new2_keycloak/create-realm-secert.yml:23
> skipping: [10.164.237.140] => {
> "changed": false,
> "skip_reason": "Conditional result was False"
> }
> META: ran handlers
> META: ran handlers
>
>
>
>
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
>
ansible-proje...@googlegroups.com <mailto:
ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
>
https://groups.google.com/d/msgid/ansible-project/556bc277-860c-4c09-82b5-6b0183e13d81%40googlegroups.com
> <
https://groups.google.com/d/msgid/ansible-project/556bc277-860c-4c09-82b5-6b0183e13d81%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.