I am trying to check if a given mount point exists for each host in my playbook. I am trying to generate a kind of report by printing Success or Failed using if-else, loops and flags (need something better than flags) inside a jinja2 template. First i am looping through all hosts and for each host i am looping through each ansible_mount and checking for a matching, setting a flag:
##Check if drive exists and have enough free space
{% for i in play_hosts %}
{% set foundDIR = false %}
{% for mountInfo in ansible_mounts %}
{% if DIR == mountInfo.mount %}
{% set foundDIR = true %}
{% if mountInfo.size_available > size %}
{{i}}: Success
{% else %}
{{i}}: Failed
{% endif %}
{% endif %}
{% endfor %}
{% if foundDIR == false %}
{{i}}: Failed - Mount dir {{DIR}} not found
{% endif %}
{% endfor %}
The problem is that i do not think this flag is properly as i always see the line - Failed - Mount dir {{DIR}} not found
I am not sure what i am doing wrong here. Is this a syntax problem or this is never going to work ? If it is the latter, then what should i do to achieve this ?
I am trying to check if a given mount point exists for each host in my
playbook. I am trying to generate a kind of report by printing Success or
Failed using if-else, loops and flags (need something better than flags)
Flag? Do you mean facts?
inside a jinja2 template. First i am looping through all hosts and for each
host i am looping through each ansible_mount and checking for a matching,
setting a flag:
To get the variables for a host you must use hostvars.
It's the same principle as the other mail where I showed you an example.
You need to study that and understand how it works.
The problem is that i do not think this flag is properly as i always see
the line - Failed - Mount dir {{DIR}} not found
The problem is not facts they have the information, you need to use hostvars.
I am not sure what i am doing wrong here. Is this a syntax problem or this
is never going to work ? If it is the latter, then what should i do to
achieve this ?
If you do it correctly it will work.
You need to study my example in my answer in your previous question. When you understand how that work you should be able to make this one work.
I mean flags, something we use in programming with with double loops to check outside the loop if something is found. I am trying to compare 2 different lists here and setting a flag in inner loop.