https://github.com/farisc0de/ansiblemoduleboilerplate
Bash Ansible Module Boilerplate
https://github.com/farisc0de/ansiblemoduleboilerplate
Last synced: 4 months ago
JSON representation
Bash Ansible Module Boilerplate
- Host: GitHub
- URL: https://github.com/farisc0de/ansiblemoduleboilerplate
- Owner: farisc0de
- License: mit
- Created: 2024-06-26T04:00:11.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-26T04:12:41.000Z (almost 2 years ago)
- Last Synced: 2025-02-16T18:38:49.586Z (over 1 year ago)
- Language: Shell
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ansible Module Boilerplate
Bash Ansible Module Boilerplate
## Features
- [x] Argument parsing
- [x] Argument validation
- [x] Help message
## Exmaple
```bash
#!/bin/bash
source $1
// Add your functions here
function action1() {
// Add your code here
if [ $? -ne 0 ]; then
failed=true
msg="Failed to perform action1"
print_error "$failed" "$msg"
fi
print_status "true" "Action1 completed successfully"
}
function print_error() {
printf '{"failed": %s, "msg": "%s"}' "$1" "$2"
exit 1
}
function print_status() {
printf '{"changed": %s, "msg": "%s"}' "$1" "$2"
}
case $action in
action1)
// Add your code here
*)
failed=true
msg="Invalid action"
print_error "$failed" "$msg"
;;
esac
exit 0
```
## How to use
```bash
ansible-playbook -i localhost, -e action=action1 -e var1=value1 -e var2=value2 -m /path/to/module
```
```yaml
- name: Test module
hosts: localhost
tasks:
- name: Test action1
mymodule:
action: action1
var1: value1
var2: value2
```
## License
MIT