Comments (4)
Hi @lingxiao26
I tried to build the example and seems to work as expected, and the files are embed in the binary.
That what I did, can you try it?
go-ansible/examples/ansibleplaybook-simple-embedfs $ go build .
go-ansible/examples/ansibleplaybook-simple-embedfs $ ls
ansibleplaybook-simple-embedfs ansibleplaybook-simple-embedfs.go embedfs
go-ansible/examples/ansibleplaybook-simple-embedfs $ mv ansibleplaybook-simple-embedfs /tmp
go-ansible/examples/ansibleplaybook-simple-embedfs $ cd /tmp
aleix@EDO-LAP-2060: /tmp
❯ ./ansibleplaybook-simple-embedfs
Copying file from the embedded filesystem 'embedfs/inventory.ini' to '/tmp/ansibleplaybook-simple-embedfs-2176152074/inventory.ini'
Copying file from the embedded filesystem 'embedfs/site.yml' to '/tmp/ansibleplaybook-simple-embedfs-2176152074/site.yml'
Copying file from the embedded filesystem 'embedfs/site2.yml' to '/tmp/ansibleplaybook-simple-embedfs-2176152074/site2.yml'
PLAY [all] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [127.0.0.1]
TASK [ansibleplaybook-simple] **************************************************
ok: [127.0.0.1] =>
msg: Your are running 'ansibleplaybook-simple-embedfs' example
PLAY RECAP *********************************************************************
127.0.0.1 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
PLAY [all] *********************************************************************
TASK [ansibleplaybook-simple] **************************************************
ok: [127.0.0.1] =>
msg: Your are running 'ansibleplaybook-simple-embedfs' example on site2.yml
PLAY RECAP *********************************************************************
127.0.0.1 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
from go-ansible.
One suggestion. What I ended up doing is creating structs that you can yaml-marshal into viable ansible playbooks. It's not perfect and you might run into issues doing this with some of the more complex ansible modules. Then when I go to run a playbook, I serialize it into TMPDIR, run it from there, then remove the playbook. I no longer have playbooks embedded in the code or have long-living playbooks on disk.
For example, here is a playbook that uses ansible copy module:
type CopyPlaybook struct {
Name string `yaml:"name"`
Hosts string `yaml:"hosts"`
GatherFacts bool `yaml:"gather_facts,omitempty"`
Become bool `yaml:"become,omitempty"`
IgnoreErrors bool `yaml:"ignore_errors,omitempty"`
AnyErrorsFatal bool `yaml:"any_errors_fatal,omitempty"`
Tasks []CopyModuleTask `yaml:"tasks"`
}
// CopyModuleTask encapsulates options for the ansible copy module
type CopyModuleTask struct {
Name string `yaml:"name"`
Register string `yaml:"register,omitempty"`
FailedWhen []string `yaml:"failed_when,omitempty"`
DelegateTo string `yaml:"delegate_to,omitempty"`
Module CopyModuleArgs `yaml:"ansible.builtin.copy"`
}
// CopyModuleArgs encapsulates ansible copy module args
type CopyModuleArgs struct {
Src string `yaml:"src,omitempty"`
RemoteSrc string `yaml:"remote_src,omitempty"`
Dest string `yaml:"dest,omitempty"`
Owner string `yaml:"owner,omitempty"`
Group string `yaml:"group,omitempty"`
Mode string `yaml:"mode,omitempty"`
Content string `yaml:"content,omitempty"`
Follow string `yaml:"follow,omitempty"`
Backup string `yaml:"backup,omitempty"`
Validate string `yaml:"validate,omitempty"`
}
Im actually working on making this more generic so each module doesn't need dedicated structs.
from go-ansible.
Hi @lingxiao26!
Did you have the chance to validate the example again or review the suggestion made by @rhugga?
from go-ansible.
I will close the issue due to inactivity. Feel free to open a new issue if you need further assistance!
Thank you!
from go-ansible.
Related Issues (20)
- Extra vars issue in playbooks HOT 2
- Feature Request: GO:Embed HOT 12
- real time output HOT 5
- Generate vaulted extra-vars
- Change the Executor signature to 'Execute(ctx context.Context, command []string, options ...ExecuteOptions)' HOT 1
- Ansible Configuration Support HOT 6
- SSH StrictHostKeyChecking HOT 3
- [Question] Can we use alias for inventory? HOT 3
- execute.WithEnvVar is not working HOT 4
- Suggestion for a Feature to Execute Inventory-Related Commands HOT 3
- Implementing support for `go-embed-python` HOT 9
- Example for winrm connection configuration HOT 2
- Many ssh <defunct> then using library. HOT 5
- How to properly provide multiple ssh extra args HOT 3
- cannot use go get v2 HOT 3
- extra vars not being set HOT 6
- Error decoding results stdout_lines HOT 3
- Unable to see prompt text HOT 1
- Inquiry about Referencing Executed Processes in DefaultExecute Object HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-ansible.