Reputation: 45
Looking for way to fetch "just" size_available of a particular mount point on remote host from ansible_hosts fact and set that as fact variable in playbook. Can't really figure that out - please share code snippet.
Upvotes: 0
Views: 2868
Reputation: 96
For a solution that does not depend on the json_query
filter, which requires the jmespath
module, you can use the built-in selectattr
filter instead:
- debug:
msg: "{{ (ansible_mounts | selectattr('mount', 'equalto', '/') | list)[0].size_available }}"
Upvotes: 0
Reputation: 11
For Ansible 2.8.2 I found that the above solution didn't work and failed with:
templating error while templating string: expected token ',', got 'string'.
The following, however, worked (moving the query text to a variable):
- debug:
msg: "{{ ansible_mounts|json_query(jmesquery) | first }}"
vars:
jmesquery: "[?mount == `/`].size_available"
gives:
"msg": "40047341568"
Upvotes: 1
Reputation: 68034
JSON Query Filter would do the job. For example size_available for mount: /
- debug:
msg: "{{ ansible_mounts|json_query('[?mount == `/`].size_available') }}"
gives:
"msg": [
40047341568
]
Upvotes: 0