-
-
Save maurizi/325387aee9ea94fbf903 to your computer and use it in GitHub Desktop.
@echo off | |
cygwin-shim.bat /bin/ansible-galaxy %* |
@echo off | |
cygwin-shim.bat /bin/ansible-playbook %* |
@echo off | |
set COMMAND=%1 | |
REM If you used the standard Cygwin installer this will be C:\cygwin | |
set CYGWIN=%USERPROFILE%\.babun\cygwin | |
REM You can switch this to work with bash with %CYGWIN%\bin\bash.exe | |
set SH=%CYGWIN%\bin\zsh.exe | |
if not exist "%SH%" ( | |
echo cygwin's sh.exe not found. Did you delete %CYGWIN% ? | |
exit /b 255 | |
) | |
"%SH%" -c "[[ -x "%COMMAND%" ]]" | |
if not errorlevel 0 ( | |
echo %COMMAND% not found. Did you uninstall it ? | |
exit /b 255 | |
) | |
"%SH%" -c "%*" |
Thanks everyone, this post really helped me out.
The private key configuration got moved inside the auto-generated inventory file in vagrant 1.7.3.
Here is an updated version that works for me, I've only tested this on vagrant 1.7.4:
@echo off
REM If you used the stand Cygwin installer this will be C:\cygwin
set CYGWIN=%USERPROFILE%\.babun\cygwin
REM You can switch this to work with bash with %CYGWIN%\bin\bash.exe
set SH=%CYGWIN%\bin\zsh.exe
REM extract the location of the inventory file into an env variable. Next, update the contents of the inventory file with the path to the private key file, relative to the cygwin root directory. extract the private key path and change the permissions of the private key.
"%SH%" -c "export INV_FILE=`echo %* | sed -E 's/.*--inventory-file=([^ ]*).*/\1\/vagrant_ansible_inventory/'` && cat $INV_FILE | sed -E 's/(ansible_ssh_private_key_file=).*(\/home\/'$USER')([^ ]*)/\1\2\3/' > new_file; cp new_file $INV_FILE; rm new_file && export PRIV_KEY=`cat $INV_FILE | tr '\n' ' ' | sed -E 's/.*ansible_ssh_private_key_file=([^ ]*)/\1/'` && chmod 600 $PRIV_KEY; ls -la $PRIV_KEY"
"%SH%" -c "export ANSIBLE_SSH_ARGS='-o ControlMaster=no' && ansible-playbook %*"
Here is a working solution for Vagrant 1.7.3+ on Windows, supports multiple hosts in inventory with multiple keys.
https://github.com/rivaros/ansible-playbook-shim
Problem of repeated project root path with ansible/vars/app with ansible-playbook.bat
Copied ansible-playbook.bat from
http://www.azavea.com/blogs/labs/2014/10/running-vagrant-with-ansible-provisioning-on-windows/
I got the following command expression, it's executable with vagrant/Windows/babun:
"d:\yushen\bin\.babun\cygwin\bin\bash.exe" -c "/bin/ansible-playbook --user=vagrant --connection=ssh --timeout=30 --limit=all --inventory-file=D:/yushen/dev/clojure/cas-reports/ansible/dev D:/yushen/dev/clojure/cas-reports/ansible/provision.yml"
ERROR: file could not read: /cygdrive/d/yushen/dev/clojure/cas-reports/D:/yushen/dev/clojure/cas-reports/ansible/vars/app
The error above seems that in the path for ansible/vars/app the path for my project d:/yushen/dev/clojure/cas-reports
was repeated in front of it as /cygdrive/d/yushen/dev/clojure/cas-reports
(typical cygwin expression!)
I examed the ansible/provision.yml
but could not find any clue. Please help to give me some pointer. Thanks,
Here is the content of ansible/provision.yml
portion related to app:
---
- hosts: app
sudo: true
vars_files:
- vars/app
tasks:
- name: Create the project directory.
file: state=directory path={{project_root}}
- name: Install required system packages.
apt: pkg={{item}} state=installed update-cache=yes
with_items: "{{system_packages}}"
- name: Get leiningen
get_url: url=https://raw.github.com/technomancy/leiningen/stable/bin/lein dest="{{lein_dir}}"
- name: Leiningen permissions
file: path={{lein_dir}} mode=0755
- name: Download project dependencies
shell: su - vagrant -c 'cd /var/projects/{{project_name}}; lein deps'
- name: Upload nREPL upstart config file
copy: src=files/nrepl-upstart.conf dest=/etc/init/nrepl.conf
- name: Start nREPL server
service: name=nrepl state=started
- name: Make app log directory
file: state=directory path=/var/log/{{project_name}} owner=vagrant group=vagrant
where should i place the ansible-playbook.bat file?
FWIW, I use this sort of command since I want to mimic logging in.
c:\cygwin64\bin\bash.exe -l -c "echo 'the above is from my login script'"
JAVA_HOME is C:\Java\jdk1.8.0_241
the above is from my login script
@woodcoder, this post really helped me out and I ended up handling the private_keys somewhat differently: https://gist.github.com/jonathanhle/ff41bafb7c66efd72f78
Seems to work for me just fine - I'm not sure why I have to cd to specific directory to chmod/setfacl the private_key, but it does work on my Windows machine. Hope it works for you.