Reputation: 1242
How do I create a list of Subversion repositories (using svnadmin create
) with Ansible only if they do not already exist?
Upvotes: 4
Views: 691
Reputation: 1242
The key is to use the creates
argument for the command
module, which tells Ansible not to re-run the command if the given path exists. Here is an example playbook:
---
- hosts: all
vars:
- svn_repositories: ['test1', 'test2']
- svn_data_dir: /var/svn
tasks:
- name: Create missing svn repositories
command: "svnadmin create '{{svn_data_dir}}/{{item}}'"
args:
creates: "{{svn_data_dir}}/{{item}}/README.txt"
with_items: "{{svn_repositories}}"
Upvotes: 4