When var1 == "yes" and var2 == "no"

9 views
Skip to first unread message

Jesse Lyon

unread,
Feb 11, 2020, 12:44:53 PM2/11/20
to Ansible Project
So,

I'm having fits with when conditionals matching strings
No matter what I do, it applies each conditional, the combination of the variables doesn't seem to count for ... anything.

what the heck am I doing wrong? additionally, is there a better way to do this?

  - name: H - Set FIM Flag - RW
    win_domain_group
:
     
when: share_fim_managed == "yes" and share_azure_managed == "no"
      domain_server
: "{{ h_domain_server }}"
      domain_username
: "{{ h_domain_username }}"
      domain_password
: "{{ h_domain_password }}"
      scope
: global
      name
: "{{ h_g_prefix }}{{ g_name }}{{suffix_RW}}"
      attributes
:
        NCHIDMMGI
: FIM Managed - '{{ dateformat }}'
 
 
- name: H - Set Azure Flag - RW
    win_domain_group
:
      domain_server
: "{{ h_domain_server }}"
      domain_username
: "{{ h_domain_username }}"
      domain_password
: "{{ h_domain_password }}"
      scope
: global
      name
: "{{ h_g_prefix }}{{ g_name }}{{suffix_RW}}"
      attributes
:
        NCHIDMMGI
: Azure Managed - '{{ dateformat }}'
     
when: share_fim_managed == "no" and share_azure_managed == "yes"
 
- name: R - Set FIM/Azure Flag - RW
    win_domain_group
:
      domain_server
: "{{ r_domain_server }}"
      domain_username
: "{{ r_domain_username }}"
      domain_password
: "{{ r_domain_password }}"
      scope
: global
      protect
: yes
      name
: "{{ r_g_prefix }}{{ g_name }}{{suffix_RW}}"
      attributes
:
       NCHIDMMGI
: FIM / Azure Managed - '{{ dateformat }}'
     
when: share_fim_managed == "yes" and share_azure_managed == "yes"




## from the include file


share_fim_managed
: "no"
share_azure_managed
: "yes"

Stefan Hornburg (Racke)

unread,
Feb 11, 2020, 12:51:14 PM2/11/20
to ansible...@googlegroups.com
On 2/11/20 6:44 PM, Jesse Lyon wrote:
> So,
>
> I'm having fits with when conditionals matching strings
> No matter what I do, it applies each conditional, the combination of the variables doesn't seem to count for ... anything.
>
> what the heck am I doing wrong? additionally, is there a better way to do this?

Hello Jessie,

it looks like your indentation is wrong. when is a task parameter and not a module parameter:

- name: ...
win_domain_group:
domain_server:"{{ h_domain_server }}"
...
when: share_fim_managed =="yes"andshare_azure_managed =="no"

Regards
Racke

>
> |
>   -name:H -SetFIM Flag-RW
>     win_domain_group:
>       when:share_fim_managed =="yes"andshare_azure_managed =="no"
>       domain_server:"{{ h_domain_server }}"
>       domain_username:"{{ h_domain_username }}"
>       domain_password:"{{ h_domain_password }}"
>       scope:global
>       name:"{{ h_g_prefix }}{{ g_name }}{{suffix_RW}}"
>       attributes:
>         NCHIDMMGI:FIM Managed-'{{ dateformat }}'
>  
>   -name:H -SetAzureFlag-RW
>     win_domain_group:
>       domain_server:"{{ h_domain_server }}"
>       domain_username:"{{ h_domain_username }}"
>       domain_password:"{{ h_domain_password }}"
>       scope:global
>       name:"{{ h_g_prefix }}{{ g_name }}{{suffix_RW}}"
>       attributes:
>         NCHIDMMGI:AzureManaged-'{{ dateformat }}'
>       when:share_fim_managed =="no"andshare_azure_managed =="yes"
>   -name:R -SetFIM/AzureFlag-RW
>     win_domain_group:
>       domain_server:"{{ r_domain_server }}"
>       domain_username:"{{ r_domain_username }}"
>       domain_password:"{{ r_domain_password }}"
>       scope:global
>       protect:yes
>       name:"{{ r_g_prefix }}{{ g_name }}{{suffix_RW}}"
>       attributes:
>        NCHIDMMGI:FIM /AzureManaged-'{{ dateformat }}'
>       when:share_fim_managed =="yes"andshare_azure_managed =="yes"
>
>
>
>
> ## from the include file
>
>
> share_fim_managed:"no"
> share_azure_managed:"yes"
> |
>
> --
> 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/220f3ee5-5c28-42ee-befa-429ffa43b249%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/220f3ee5-5c28-42ee-befa-429ffa43b249%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Jesse Lyon

unread,
Feb 11, 2020, 1:05:27 PM2/11/20
to Ansible Project
Perfect!

I didn't realize the indentation had to be outside the module parameter, the example I was using was poorly written it seems.

I appreciate the help Stefan!

--
Jess

Hugo Gonzalez

unread,
Feb 11, 2020, 4:34:28 PM2/11/20
to ansible...@googlegroups.com



On 2/11/20 11:44 AM, Jesse Lyon wrote:
So,

I'm having fits with when conditionals matching strings
No matter what I do, it applies each conditional, the combination of the variables doesn't seem to count for ... anything.

what the heck am I doing wrong? additionally, is there a better way to do this?


Are you actually comparing the strings "yes" and "no" to the variables? If they're actual booleans, you will be better off by doing:

when: share_fim_managed and not share_azure_managed

when: not share_fim_managed and share_azure_managed

when: share_fim_managed and share_azure_managed


All nonempty strings are true, even if they contain the strings "false" or "true", you should be careful when comparing truth values. See here:


---
- hosts: localhost
  vars:
    truestringvar: "true"
    falsestringvar: "false"
    trueboolvar: true
    falseboolvar: false

  tasks:
    - debug:
        msg: Since booleans matter, this message is not shown.
      when: trueboolvar == 'true'
    - debug:
        msg: boolean values DO matter (this string is shown)
      when: trueboolvar
    - debug:
        msg: The string that says false is not false, this message will not be shown
      when: not falsestringvar





Reply all
Reply to author
Forward
0 new messages