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.
MIT License
872 stars 142 forks source link

Create a container executor #116

Open apenella opened 1 year ago

apenella commented 1 year ago

What Execute ansible command inside a container

kolcak commented 1 year ago

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

apenella commented 1 year ago

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!