Reputation: 4098
tl;dr;
hg clone ssh://[email protected]/team/repo ~/prod/
fails with "destination is not empty" if ~/prod/ is not empty. Can I force cloning?
I am trying to write my first Ansible playbook that should deploy my code from a Bitbucket Mercurial repository to my server. There is a deployment path, ~/prod
, which contains all code files as well as the data in ~/prod/media
and ~/prod/db.db
. To make sure the playbook works even if the ~/prod
directory is empty or doesn't exist, this is what I have so far:
- name: create directory
file: path=/home/user/prod state=directory
- name: clone repo
hg:
repo: ssh://[email protected]/team/repo
dest: /home/user/prod
force: yes
In my understanding, it ensures that the deployment directory exists and then clones the repo there. It works beautifully if the directory doesn't exist or is empty. However, as soon as I've cloned the repo once, this playbook fails with destination is not empty
.
I can move media and db.db out first, then delete all other files, then clone, then move the data back. But it looks cumbersome.
I simply want to force cloning. But I cannot find the way to do it. Presumably this is so wrong that Mercurial won't allow me doing this. Why and what's a better way to go?
Upvotes: 2
Views: 2892
Reputation: 4098
Though I haven't yet read it anywhere, looks like force-cloning is impossible. The two alternatives then are, as explained in another thread on the same topics:
hg init /home/user/prod
and then hg pull ssh://[email protected]/team/repo /home/user/prod; hg update -C -R /home/user/prod
.With the second one, it is possible to optimise the Ansible task, to perform this action only if the target directory doesn't contain .hg:
- name: recreate repo
command:
hg ssh://[email protected]/team/repo -R /home/user/prod
creates=/home/user/prod/.hg # <-- only execute command if .hg does not exist
- name: update files
hg:
repo: ssh://[email protected]/team/repo
dest: /home/user/prod
clone: no
update: yes # optional, for readability
force: yes
notify: "restart web services"
Upvotes: 6