Difference between revisions of "Performing tasks based on whether file or folder exists"
From Notes_Wiki
(Created page with "<yambe:breadcrumb>Ansible_tips_and_tricks|Ansible tips and tricks</yambe:breadcrumb> =Performing tasks based on whether file or folder exists= Now many modules already suppor...") |
m |
||
Line 1: | Line 1: | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[System administration tools]] > [[Ansible|ansible]] > [[Ansible tips and tricks]] > [[Performing tasks based on whether file or folder exists]] | |||
Now many modules already support creates attribute to skip certain step if a there is already a given file or folder. But certain modules such as template module do not support such option. In such cases to copy template only when a certain file exists or does not exists following combination of stat and template module can be used: | Now many modules already support creates attribute to skip certain step if a there is already a given file or folder. But certain modules such as template module do not support such option. In such cases to copy template only when a certain file exists or does not exists following combination of stat and template module can be used: | ||
Line 14: | Line 13: | ||
- restart iptables | - restart iptables | ||
</pre> | </pre> | ||
[[Main Page|Home]] > [[CentOS]] > [[CentOS 6.x]] > [[System administration tools]] > [[Ansible|ansible]] > [[Ansible tips and tricks]] > [[Performing tasks based on whether file or folder exists]] |
Latest revision as of 11:52, 28 July 2022
Home > CentOS > CentOS 6.x > System administration tools > ansible > Ansible tips and tricks > Performing tasks based on whether file or folder exists
Now many modules already support creates attribute to skip certain step if a there is already a given file or folder. But certain modules such as template module do not support such option. In such cases to copy template only when a certain file exists or does not exists following combination of stat and template module can be used:
- stat: path=/etc/sysconfig/iptables register: iptables_rules - name: Copy iptables file if not present already template: src=iptables dest=/etc/sysconfig/iptables when: iptables_rules.stat.exists == False notify: - restart iptables
Home > CentOS > CentOS 6.x > System administration tools > ansible > Ansible tips and tricks > Performing tasks based on whether file or folder exists