# Use Ansible ## Run with docker ssh agent side proxy ### build docker images ```sh git clone -q --depth 1 --branch master https://github.com/arcodange/ssh-agent.git /tmp/ssh-agent (cd /tmp/ssh-agent ; docker build -t docker-ssh-agent:latest -f Dockerfile . ; rm -rf /tmp/ssh-agent) (cd ansible; docker build -t arcodange-ansible:0.0.0 .) ``` ### run in container ```sh # git clone -q --depth 1 --branch master https://github.com/arcodange/ssh-agent.git /tmp/ssh-agent # (cd /tmp/ssh-agent ; docker build -t docker-ssh-agent:latest -f Dockerfile . ; rm -rf /tmp/ssh-agent) # (cd ansible; docker build -t arcodange-ansible:0.0.0 .) docker run -d --name=ssh-agent docker-ssh-agent:latest docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/.ssh -it docker-ssh-agent:latest ssh-add /root/.ssh/id_rsa docker run --rm -u root --name test --volumes-from=ssh-agent -v $PWD:/home/arcodange/code arcodange-ansible:0.0.0 \ ansible-playbook ansible/arcodange/factory/playbooks/setup/setup.yml -i ansible/arcodange/factory/inventory -vv ``` ### a tool to reuse a ssh agent (not required) ```sh FIND_SSH_AGENT=$HOME/.local/bin/ssh-find-agent curl -s https://raw.githubusercontent.com/wwalker/ssh-find-agent/master/ssh-find-agent.sh > $FIND_SSH_AGENT chmod +x $FIND_SSH_AGENT echo 'ssh_find_agent "$@"' >> $FIND_SSH_AGENT which brew && brew install coreutils # if on macos ``` ```sh eval "$(ssh-agent -s)" ssh-add ~/.ssh/id_rsa ``` ## dev ### test an expression ```sh ansible -i ,localhost -c local localhost -m raw -a "echo hello world {{ inventory_hostname }} : {{ hostvars | to_nice_json | regex_replace(\"['\n]\",' ') }}" ```