Hi

Ok, I think I know what you're doing here.
ansible_mounts is an ansible fact - a magi variable defined by Ansible
during runtime, but you are instructing Ansible not to gater facts
with  gather_facts: no, that's why Ansible can not recognize the
ansible_mounts variable, so remove the "gather_facts: no" line.

Then, with the following:
  vars_files:
      - /etc/ansible/xyz/pre-deploy/vars/main.yml
you are overwriting the ansible_mounts fact - you loose the information on
mounts. Remove the above as well.

Last one
when: item.mount == mountname
mountname is not defined anywhere. This will fail. I don't know what you
need it for.

I strongly recommend you to read at least the Ansible tutorial before you
continue doing anything with Ansible or you will have a baaad time :)

Piotr


wt., 4 gru 2018 o 12:56 <[email protected]> napisał(a):

> Hi Piotr,
>
> Thank you for your quick response. I am trying to check if the available
> disk space is greater than 30% and declared mounts as variables but still
> it is failing. COuld you please help.
>
> Playbook.yml
> ---
> - hosts: all
>   gather_facts: no
>   vars_files:
>       - /etc/ansible/xyz/pre-deploy/vars/main.yml
>
>   tasks:
>   - name: Ensure that free space on the tested volume is greater than 15%
>     assert:
>       that: item.size_available > item.size_total|float * 0.3
>       msg: Disk space has reached 85% threshold
>     when: item.mount == mountname
>     with_items: "{{ ansible_mounts }}"
>
>
> vars/main.yml
> ansible_mounts:
> - { mount: '/tmp','xyz' }
>
> ERROR:
> FAILED! => {"msg": "The conditional check 'item.size_available >
> item.size_total|float * 0.3' failed. The error was: error while evaluating
> conditional (item.size_available > item.size_total|float * 0.3):
> 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute
> 'size_total'"}
>
>
>
> On Tuesday, December 4, 2018 at 3:09:34 PM UTC+5:30, Piotr Owcarz wrote:
>>
>> Hi
>>
>> You are declaring ansible_mounts as a list of strings. It literally is:
>> ansible_mounts: ['xyz', 'abc']. Ansible is complaining, that the string
>> 'xyz' does not have a 'mount' property. You are obviously missing a step,
>> where you actually check the available space :)
>>
>> Piotr
>>
>>
>>
>>
>> wt., 4 gru 2018 o 08:11 <[email protected]> napisał(a):
>>
>>> Hi Experts,
>>>
>>> I am trying to check the diskspace on remote servers but it failing .
>>> Could someone please help.
>>>
>>> Playbook.yml
>>>
>>> ---
>>> - hosts: all
>>>   gather_facts: no
>>>   vars_files:
>>>       - /etc/ansible/xyz/pre-deploy/vars/main.yml
>>>
>>>   tasks:
>>>   - name: Ensure that free space on the tested volume is greater than 15%
>>>     assert:
>>>       that: item.size_available > item.size_total|float * 0.3
>>>       msg: Disk space has reached 85% threshold
>>>     when: item.mount == mountname
>>>     with_items: "{{ ansible_mounts }}"
>>>
>>>
>>> vars/main.yml
>>>
>>> ansible_mounts:
>>> - xyz
>>> - abc
>>>
>>> ERROR:
>>>
>>> FAILED! => {"msg": "The conditional check 'item.mount == mountname'
>>> failed. The error was: error while evaluating conditional (item.mount ==
>>> mountname): 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no
>>> attribute 'mount'\n\nThe error appears to have been in
>>> '/etc/ansible/xyz/pre-deploy/tasks/disk.yml': line 8, column 5, but may\nbe
>>> elsewhere in the file depending on the exact syntax problem.\n\nThe
>>> offending line appears to be:\n\n  tasks:\n  - name: Ensure that free space
>>> on the tested volume is greater than 15%\n    ^ here\n"}
>>>
>>> --
>>> 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 [email protected].
>>> To post to this group, send email to [email protected].
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/ansible-project/cd064e4b-79fb-4788-9607-567a64421f93%40googlegroups.com
>>> <https://groups.google.com/d/msgid/ansible-project/cd064e4b-79fb-4788-9607-567a64421f93%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/b8335190-8860-4f24-b2a5-40e3953e6a21%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/b8335190-8860-4f24-b2a5-40e3953e6a21%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CACHJvyNxsrp-JV5L42fT0kgP9VtAuH2gEYusEVny9U_YFi0-hg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to