apenella / go-ansible

Go-ansible is a Go package that enables the execution of ansible-playbook or ansible commands directly from Golang applications. It supports a wide range of options for each command, enabling smooth integration of Ansible functionality into your projects.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create a container executor

apenella opened this issue · comments

What
Execute ansible command inside a container

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. :(

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!