When Condition check is not working in a list as expected.

閲覧: 13 回
最初の未読メッセージにスキップ

Pandu jh

未読、
2019/02/28 7:52:312019/02/28
To: Ansible Project
When Condition check is not working in a list as expected.

My requirement is 

Playbook should not fail If all the three mentioned variables have "no_share" value.
But it's failing not sure what causing this issue.



    - debug:  var=open_shares_info
    - debug:  var=linked_dirs_list
    - debug:  var=nfs_hard_mounts

    - name: Fail Playbook Execution
      fail:
        msg:  "Make sure to unshare/unmount all NFS shares in NFS clients"
      when:  ("'no_share' not in open_shares_info") and  ("'no_share' not in linked_dirs_list") and and ("'no_share' not in nfs_hard_mounts")



TASK [debug] *******************************************************************************************************************************************
ok: [rchadm01] => {
    "open_shares_info": "no_share"
}

TASK [debug] *******************************************************************************************************************************************
ok: [rchadm01] => {
    "linked_dirs_list": "no_share"
}

TASK [debug] *******************************************************************************************************************************************
ok: [rchadm01] => {
    "nfs_hard_mounts": "no_share"
}

TASK [Fail Playbook Execution] *************************************************************************************************************************
fatal: [rchadm01]: FAILED! => {"changed": false, "msg": "Make sure to unshare/unmount all NFS shares in NFS clients"}

Kai Stian Olstad

未読、
2019/02/28 14:20:412019/02/28
To: ansible...@googlegroups.com
On 28.02.2019 13:52, Pandu jh wrote:
> When Condition check is not working in a list as expected.
>
> My requirement is
>
> Playbook should not fail If all the three mentioned variables have
> "no_share" value.
> But it's failing not sure what causing this issue.
>
>
>
> - debug: var=open_shares_info
> - debug: var=linked_dirs_list
> - debug: var=nfs_hard_mounts
>
> - name: Fail Playbook Execution
> fail:
> msg: "Make sure to unshare/unmount all NFS shares in NFS clients"
> when: ("'no_share' not in open_shares_info") and ("'no_share' not
> in linked_dirs_list") and and ("'no_share' not in nfs_hard_mounts")

In Jinja template that when uses, quotes, single and double, means this is a string.
So when you put a double quote around the hole expressing you are making it a sting.

In you when its

a_string and a_string and a_string

Remove the double quotes and it should work. (and also remove the double and)


--
Kai Stian Olstad

Pandu jh

未読、
2019/03/01 11:01:232019/03/01
To: Ansible Project
Thank you, It worked.

Pandu jh

未読、
2019/03/01 11:06:172019/03/01
To: Ansible Project
One more Requirement Kai,

I need to test the condition If stdout_lines is not defined or the stdout_lines length is 0, then open_shares_info variable should have the no_share value.
Could you check below syntax is correct, I am getting an error when I run it.

  - set_fact:
        open_shares_info: "{{  nfs_open_share.stdout_lines if nfs_open_share.stdout_lines|length != 0 or nfs_open_share.stdout_lines is defined else 'no_share' }}"

Kai Stian Olstad

未読、
2019/03/04 6:12:242019/03/04
To: ansible...@googlegroups.com
On 01.03.2019 17:06, Pandu jh wrote:
> One more Requirement Kai,
>
> I need to test the condition If stdout_lines is not defined or the
> stdout_lines length is 0, then open_shares_info variable should have
> the
> no_share value.
> Could you check below syntax is correct, I am getting an error when I
> run
> it.
>
> - set_fact:
> open_shares_info: "{{ nfs_open_share.stdout_lines if
> nfs_open_share.stdout_lines|length != 0 or nfs_open_share.stdout_lines
> is
> defined else 'no_share' }}"

Why don't you just test it and see if it works.

--
Kai Stian Olstad
全員に返信
投稿者に返信
転送
新着メール 0 件