Ansible stat module
I use the Ansible stat module mostly for conditional statements.
For example, only when directory
/var/www/phpmyadmin does not exist include the task for installing PHPMyAdmin.
But of course, there are a lot of other uses for this module then the one I use most.
It does this by doing the following two things:
- get all system-information about the directory
- execute statement, depending on values from the fetched system-information
But there are a lot of uses for the stat module.
The official documentation for the stat module is on, ofcourse, the Ansible website: http://docs.ansible.com/ansible/stat_module.html
# file: install.yml # install PHPMyAdmin when it's not installed already - name: PHPMyAdmin | check the need for installment stat: path: /var/www/html/phpmyadmin register: pma # Only include the PHPMyAdmin installation-task when it's not installed yet # e.g. the directory /var/www/html/phpmyadmin does not exist - include: PHPMyAdmin | install when: pma.stat.isdir is not defined
As you can see, we’re checking against the variable
pma which holds the
stats information for our path
/var/www/html/phpmyadmin. This variable holds a lot more then just the
The full list of information returned by the Ansible stat module:
I will continue to update this page as needed.