Is there a way to checkout the whole directory from svn using Ansible?
Below play checks the content of that directory out, but I would also want the directory itself to be checked out.
So do I have to create the directory first and then checkout the content?
Basically my question is about checking out the content and directory my-1.0.0
in /home/ansible/temp/deploy/
.
- name: Checking out the Ansible Playbook for the current Release in the Release directory
delegate_to: localhost
subversion:
repo: svn://build.test/my-devops-mvp/branches/my-{{my_release_version}}
dest: '/home/ansible/temp/deploy/'
in_place: yes
I am passing the variable my_release_version
as a command line parameter and, in SVN, under branches, I have a structure like:
TL;DR;
Your fix is to actually add your desired folder in the dest
parameter, because subversion will create the folder for you if it does not exists yet:
dest: /home/ansible/temp/deploy/my-{{ my_release_version }}
The Ansible subversion module actually acts exactly as the subversion checkout command.
svn checkout URL[@REV]... [PATH]
In the Ansible module, what you feed in the parameter repo
in the argument subversion is calling here URL[@REV]...
and the parameter you feed in dest
is what they call here PATH
.
In that essence, you will note that the PATH
you are checking out to when using that command, can but does not forcibly have to exist.
For example:
/tmp # ls -lR
.:
total 0
/tmp # svn co https://svn.apache.org/repos/asf/subversion/branches/1.0.x/notes/logo/16-colour svn-logo
A svn-logo/subversion_logo_notxt-16m.png
A svn-logo/subversion_logo_notxt-48m.png
A svn-logo/subversion_logo_notxt-32m.png
Checked out revision 1877849.
/tmp # ls -lR svn-logo/
svn-logo/:
total 12
-rw-r--r-- 1 root root 237 May 17 10:36 subversion_logo_notxt-16m.png
-rw-r--r-- 1 root root 292 May 17 10:36 subversion_logo_notxt-32m.png
-rw-r--r-- 1 root root 348 May 17 10:36 subversion_logo_notxt-48m.png
Also note that you can even create a full directory structure, even if it does not exists there.
/tmp # svn co https://svn.apache.org/repos/asf/subversion/branches/1.0.x/notes/logo/16-colour 1.0.X/notes/logo/16-colour
A 1.0.X/notes/logo/16-colour/subversion_logo_notxt-16m.png
A 1.0.X/notes/logo/16-colour/subversion_logo_notxt-48m.png
A 1.0.X/notes/logo/16-colour/subversion_logo_notxt-32m.png
Checked out revision 1877850.
So, as I said earlier, what hold true to the subversion commands, also holds true for the Ansible module.
Given this playbook:
- hosts: local
vars:
release: 1.0.x
tasks:
- name: svn co
subversion:
repo: https://svn.apache.org/repos/asf/subversion/branches/{{ release }}/notes/logo/16-colour
dest: /tmp/{{ release }}/notes/logo/16-colour
in_place: yes
I end up with the play:
/ # ls -lR /tmp
/tmp:
total 0
/ # ansible-playbook play.yml -i inventory.yml
PLAY [local] *********************************************************************************************
TASK [Gathering Facts] ***********************************************************************************
ok: [local]
TASK [svn co] ********************************************************************************************
changed: [local]
PLAY RECAP ***********************************************************************************************
local : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
/ # ls -lR /tmp/1.0.x/notes/logo/16-colour
/tmp/1.0.x/notes/logo/16-colour:
total 12
-rw-r--r-- 1 root root 237 May 17 10:33 subversion_logo_notxt-16m.png
-rw-r--r-- 1 root root 292 May 17 10:33 subversion_logo_notxt-32m.png
-rw-r--r-- 1 root root 348 May 17 10:33 subversion_logo_notxt-48m.png