是否有使用Ansible从svn签出整个目录的方法?在play下面,检出该目录的内容,但我也希望检出目录本身。所以我必须先创建目录然后签出内容吗?
基本上我的问题是关于检出my-1.0.0
中的内容和目录 /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
我将变量my_release_version
作为命令行参数传递,在SVN中,分支下的结构如下:
TL; DR;
您的解决方法是实际上在dest
参数中添加所需的文件夹,因为如果尚不存在,则subversion会为您创建该文件夹:
dest: /home/ansible/temp/deploy/my-{{my_release_version}}
Ansible subversion module实际上与subversion checkout command完全一样。
svn checkout URL[@REV]... [PATH]
在Ansible模块中,您在参数子版本中输入参数repo
的位置在此调用URL[@REV]...
,而在dest
中输入的参数是它们在此处的调用PATH
。
本质上,您会注意到,使用该命令时要检出的PATH
可以但不一定必须存在。
例如:
/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
还请注意,即使那里不存在完整目录结构,您也可以创建它。
/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.
所以,正如我之前说的,对subversion命令适用的内容对Ansible模块也适用。
给出此剧本:
- 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
我结束了这出戏:
/ # 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