Further to that last post on recursive file copying:
I am now trying to get a directory with files copied onto a host via rsync (instead of copying over a single .ziped bundle and then decompressing that and changing the permissions, which I can do but it takes four tasks: (i) copy, (ii) unzip, (iii) change owner, (iv) delete zip file and it is quite awkward.)
I have been playing around with this for a bit now trying to hit the magic rsync / sudo / shh incantation to get this to go smoothly and I have had no luck so far.
So in a simple task I would like to install sublime on a server under /opt/sublime2. I have the sources on my machine (as well as some config files, etc which I would all like to copy over.) (So the first step is getting the app over there.)
So question (1) on rsync itself: From a normal shell command line, how do I rsync files into a protected directory via a user who has sudo privileges. Ie I have root login disabled on the host machine, but a user on there called ‘jason’ who has sudo privileges. I have googled around for this but I must have missed how to do this…
So failing finding out how to make (1) work I created a target directory with completely open privileges as follows:
- name: create sublime install directory
file: path=/opt/sublime2/ state=directory owner=jason group=jason mode=777
Now I can rsync via the command line into this directory:
rsync --rsh=‘ssh’ --delete -rua app/SublimeText2/ cupertino12043:/opt/sublime2/
And that works.
However if I try and do this via ansible via:
- name: UpLoad the app
local_action: command rsync --rsh=‘ssh’ --delete -rua app/SublimeText2/ {{inventory_hostname}}:/opt/sublime2/
I get:
[arcbat:Installers/Linux/ansible/Setup] Setup 5(5) ⌘ ansible-playbook -i “host_cupertino.ini” cupertino.yml -K -v
sudo password:
PLAY [cupertino] **************************************************************
GATHERING FACTS ***************************************************************
ok: [cupertino12043]
TASK: [create sublime install directory] **************************************
changed: [cupertino12043] => {“changed”: true, “gid”: 1000, “group”: “jason”, “item”: “”, “mode”: “0777”, “owner”: “jason”, “path”: “/opt/sublime2/”, “size”: 4096, “state”: “directory”, “uid”: 1000}
TASK: [UpLoad the app] ********************************************************
failed: [cupertino12043] => {“failed”: true, “item”: “”, “parsed”: false}
invalid output was: Sorry, try again.
[sudo via ansible, key=nigpbfaxyragiumbhfmpsvuwlttixxih] password:
Sorry, try again.
[sudo via ansible, key=nigpbfaxyragiumbhfmpsvuwlttixxih] password:
Sorry, try again.
sudo: 3 incorrect password attempts
FATAL: all hosts have already failed – aborting
PLAY RECAP ********************************************************************
to retry, use: --limit @/Users/jason/cupertino.retry
cupertino12043 : ok=2 changed=1 unreachable=0 failed=1
It looks like it is asking for my password even though it is passwordless from the command line. What am I missing here? Is there a good guide on how to do this canonically?
Naively, it would seem to me that synchronizing a directory with files in it onto a server is a fairly basic thing to want to do in a configuration management system. I guess I am missing something since so far this is decidedly not a smooth process for me!
Is there a beta version of the synchronize command which I could install? Any recommended plugin to make this smoother in the interim?
Thanks,
Jas