Reputation: 187
i want to include this logic in my role
- name: i want to check that NFS share is accessible and R/W
module_to_check_nfs_share: touch {{ nfs_share_path }} ( for example , or cd to it)
- name: add NFS share path to elasticsearch config
template: ...
when: nfs_module == success
how to do something like this using the ansible? so my scenario is , to try write something or cd to NFS share and make sure that NFS filesystem is accessible and is ok
Upvotes: 3
Views: 1542
Reputation: 2464
You can use the stat
module to see whether a directory exists and if it is writeable. stat.writable
contains a boolean that is true
when the directory exists and is writable.
- name: Get directory status
stat:
path: /path/to/your/dir
register: dirstatus
- name: Conditional task that only runs when dir exists and is writable
template: ...
when: dirstatus.stat.writeable | default(false)
Upvotes: 6