go-ansible icon indicating copy to clipboard operation
go-ansible copied to clipboard

Create a container executor

Open apenella opened this issue 3 years ago • 2 comments

What Execute ansible command inside a container

apenella avatar Nov 19 '22 16:11 apenella

problem line: https://github.com/apenella/go-ansible/blob/master/pkg/playbook/ansiblePlaybook.go#L135

workarround:

  1. create script file ./ansible-playbook.sh
#!/bin/sh

# @see https://hub.docker.com/r/alpine/ansible
exec docker run --rm -v $(pwd)/source:/source -w /source alpine/ansible ansible-playbook "$@"

test: ./ansible-playbook.sh --help

  1. change Binary file in your project
	playbook := &playbook.AnsiblePlaybookCmd{
		....
		Binary: "./ansible-playbook.sh",
		....
	}
  1. enjoy

I tried used alias but aliases are a shell construct. They aren't passed to sub processes. :(

kolcak avatar Sep 07 '23 09:09 kolcak

Hi @kolcak Thank you very much for your workaround! The idea I have is to provide a solution that does not require an intermediate script but I will do a further evaluation when I tackle that feature. Meanwhile, I keep your approach as a plan B.

Thanks!

apenella avatar Sep 08 '23 05:09 apenella