Skip to content

Commit

Permalink
minor CI fixes, better README
Browse files Browse the repository at this point in the history
  • Loading branch information
lfkdev committed Jun 26, 2024
1 parent aae36c6 commit 601a762
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
20 changes: 7 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,38 @@ on:
jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.8'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Create config file
run: |
echo "playbook_dir: ./test_playbooks" > ansible_link/config.yml
echo "inventory_file: ./test_inventory.ini" >> ansible_link/config.yml
echo "job_storage_dir: ./test_job_storage" >> ansible_link/config.yml
mkdir test_playbooks test_job_storage
mkdir -p test_playbooks test_job_storage
touch test_inventory.ini
- name: Create test playbook
run: |
touch test_playbooks/test_playbook.yml
echo "- hosts: localhost" > test_playbooks/test_playbook.yml
echo " tasks:" >> test_playbooks/test_playbook.yml
echo " - name: Output OK" >> test_playbooks/test_playbook.yml
echo " debug:" >> test_playbooks/test_playbook.yml
echo " msg: OK" >> test_playbooks/test_playbook.yml
- name: Set ANSIBLE_API_CONFIG
run: export ANSIBLE_API_CONFIG=$GITHUB_WORKSPACE/test-config.yml

- name: show structure
- name: Set PYTHONPATH and ANSIBLE_API_CONFIG
run: |
echo "PYTHONPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV
echo "ANSIBLE_API_CONFIG=$GITHUB_WORKSPACE/ansible_link/config.yml" >> $GITHUB_ENV
- name: Show structure and environment
run: |
ls -R
echo "PYTHONPATH: $PYTHONPATH"
echo "ANSIBLE_API_CONFIG: $ANSIBLE_API_CONFIG"
- name: Run tests
run: python -m unittest discover tests
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<b>NOTE</b> Project is usable but still in early development

## Motivation
Searched for a way to run our playbooks automated without the need of AWX or other big projects while still being more stable and less error-prone than custom bash scripts. So I made Ansible-Link. This projects aims to be a KISS way to run ansible jobs remotely. Essentially a RESTful API sitting on top of [ansible-runner](https://github.com/ansible/ansible-runner)
Searched for a way to run our playbooks automated without the need of AWX or other big projects while still being more stable and less error-prone than custom bash scripts. So I made Ansible-Link. This projects aims to be a KISS way to run ansible jobs remotely. Essentially a RESTful API sitting on top of [ansible-runner](https://github.com/ansible/ansible-runner).

## Prerequisites
* Python 3.7+
Expand Down Expand Up @@ -62,6 +62,14 @@ The API documentation is available via the Swagger UI.

<img src="docs.png" alt="Ansible Link Docs">

## API Endpoints

* <code>POST /ansible/playbook: Execute a playbook</code>
* <code>GET /ansible/jobs: List all jobs</code>
* <code>GET /ansible/job/<job_id>: Get job status</code>
* <code>GET /ansible/job/<job_id>/output: Get job output</code>
* <code>GET /health: Health check endpoint</code>

## Configuration
The API configuration is stored in the `config.yml` file.
If you move your config to a different location you can use `ANSIBLE_API_CONFIG`
Expand All @@ -72,29 +80,32 @@ $ export ANSIBLE_API_CONFIG='/etc/ansible-link/config.yml'
You can customize the following settings:

```yaml
# webhook
# webhook:
# url: "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK"
# type: "slack" # "slack", "discord" or "generic" supported
# timeout: 5 # optional, default 5 seconds

# flask
host: '127.0.0.1'
port: 5001
debug: false

# webhook configuration
# webhook:
# url: "https://hooks.slack.com/services/YOUR/SLACK/WEBHOOK"
# type: "slack" # Options: slack, discord, generic
# timeout: 5 # Optional, defaults to 5 seconds

# ansible-runner
suppress_ansible_output: false
omit_event_data: false
only_failed_event_data: false

# promtetheus
metrics_port: 9090

# general
playbook_dir: '/etc/ansible/'
inventory_file: '/etc/ansible/environments/hosts'
job_storage_dir: '/var/lib/ansible-link/job-storage'
log_level: 'INFO'

# ansible-link (leave blank to allow all)
# ansible-link
playbook_whitelist: []
# playbook_whitelist:
# - monitoring.yml
Expand Down Expand Up @@ -158,14 +169,6 @@ WantedBy=multi-user.target
└── playbook_name_20230624_130000_job_id.json
```
### API Endpoints
* <code>POST /ansible/playbook: Execute a playbook</code>
* <code>GET /ansible/jobs: List all jobs</code>
* <code>GET /ansible/job/<job_id>: Get job status</code>
* <code>GET /ansible/job/<job_id>/output: Get job output</code>
* <code>GET /health: Health check endpoint</code>
## Webhook Configuration
Ansible-Link supports sending webhook notifications for job events. You can configure webhooks for Slack, Discord, or a generic endpoint. Add the following to your config.yml:
Expand All @@ -185,7 +188,7 @@ or leave it commented out to disable webhooks
Only Slack and Discord are supported for now, you can also use `generic` which will send the base JSON payload:

```json
base_payload = {
{
"event_type": event_type,
"job_id": job_data['job_id'],
"playbook": job_data['playbook'],
Expand Down

0 comments on commit 601a762

Please sign in to comment.