Skip to content

Ansible Integration

Vapor provides seamless Ansible integration for infrastructure automation, configuration management, and orchestration. Execute playbooks, manage inventory, and track execution history through an intuitive interface.

Prerequisites

  • Ansible 2.9+ installed on the system
  • SSH access to managed nodes
  • Properly configured ansible.cfg
  • Python on managed nodes
  1. From the main menu, click on Ansible
  2. Three main tabs are available:
    • Playbooks & Templates
    • Inventory
    • Executions

Playbooks Management

The Playbooks tab manages Ansible playbooks and templates.

Playbook Library

View all available playbooks:

  • Playbook name and path
  • Description (from metadata)
  • Last modified time
  • Execution count
  • Tags available
  • Variables required

Uploading Playbooks

  1. Click Upload Playbook
  2. Select method:
    • File Upload: Upload .yml files
    • Git Repository: Clone from Git
    • Direct Entry: Write in editor
  3. Configure playbook location
  4. Click Save

Playbook Organization

Organize playbooks in directories:

ansible/
├── playbooks/
│   ├── webserver/
│   │   ├── install.yml
│   │   └── configure.yml
│   ├── database/
│   │   ├── mysql.yml
│   │   └── postgresql.yml
│   └── maintenance/
│       ├── update.yml
│       └── backup.yml
└── roles/
    └── common/

Executing Playbooks

Quick Execute

  1. Click Run on a playbook
  2. Select inventory or hosts
  3. Click Execute

Advanced Execute

  1. Click Advanced Run
  2. Configure execution:
Target Selection
  • Inventory: Select inventory file
  • Limit: Specific hosts/groups
  • Tags: Run specific tags only
  • Skip Tags: Exclude certain tags
Variables
  • Extra Variables: Key-value pairs or JSON
  • Variable Files: Upload vars files
  • Vault Password: For encrypted vars
Execution Options
  • Check Mode: Dry run without changes
  • Diff Mode: Show what will change
  • Verbose Level: Debug output level
  • Forks: Parallel execution threads
  • Timeout: Connection timeout
  • Become: Privilege escalation
SSH Options
  • Private Key: SSH key file
  • SSH Password: For password auth
  • Become Password: sudo/su password
  • Connection Type: ssh, local, docker
  1. Click Execute

Playbook Templates

Vapor provides pre-built templates for common tasks:

System Templates

  • System Update: Update all packages
  • Security Hardening: Apply security baseline
  • User Management: Create/manage users
  • Firewall Setup: Configure iptables/firewalld
  • Time Sync: Configure NTP/Chrony

Application Templates

  • Web Server: Nginx/Apache setup
  • Database Server: MySQL/PostgreSQL
  • Container Runtime: Docker/Podman
  • Kubernetes Node: Join K8s cluster
  • Monitoring Agent: Prometheus/Grafana

Network Templates

  • Network Configuration: Interface setup
  • DNS Configuration: Resolver settings
  • VPN Setup: OpenVPN/WireGuard
  • Load Balancer: HAProxy/Nginx

Custom Templates

Create your own templates:

  1. Click Create Template
  2. Configure template:
    • Name and description
    • Base playbook
    • Default variables
    • Required inputs
  3. Save template for reuse

Playbook Development

Integrated Editor

Edit playbooks directly in Vapor:

  • YAML syntax highlighting
  • Auto-completion
  • Syntax validation
  • Module documentation
  • Variable references

Testing Playbooks

  1. Use Check Mode first
  2. Test on single host
  3. Review execution output
  4. Apply to production

Inventory Management

The Inventory tab manages Ansible inventory.

Inventory Types

Static Inventory

Traditional INI or YAML format:

ini
[webservers]
web1.example.com ansible_host=192.168.1.10
web2.example.com ansible_host=192.168.1.11

[databases]
db1.example.com ansible_host=192.168.1.20
db2.example.com ansible_host=192.168.1.21

[all:vars]
ansible_user=admin
ansible_ssh_private_key_file=/path/to/key

Dynamic Inventory

Generate inventory from sources:

  • Cloud Providers: AWS, Azure, GCP
  • Virtualization: VMware, Libvirt
  • Containers: Docker, Kubernetes
  • CMDB: ServiceNow, NetBox
  • Custom Scripts: Python/Shell scripts

Managing Inventory

Creating Inventory

  1. Click Create Inventory
  2. Choose type:
    • Manual: Enter hosts manually
    • Import: Upload inventory file
    • Dynamic: Configure source
  3. Add hosts and groups
  4. Set variables
  5. Click Save

Editing Inventory

  1. Click on inventory name
  2. Modify in editor:
    • Add/remove hosts
    • Create groups
    • Set host/group variables
    • Configure connections
  3. Validate syntax
  4. Save changes

Host Management

For each host:

  • Test Connection: Verify SSH access
  • Gather Facts: Collect system information
  • View Variables: See all applicable vars
  • Run Command: Execute ad-hoc commands

Host Groups

Organize hosts into groups:

  • Nested groups support
  • Group variables
  • Pattern matching
  • Dynamic group membership

Variables

Variable Precedence

From lowest to highest:

  1. All group vars
  2. Parent group vars
  3. Child group vars
  4. Host vars
  5. Host facts
  6. Play vars
  7. Task vars
  8. Extra vars

Managing Variables

  • Group Variables: Apply to all hosts in group
  • Host Variables: Specific to individual hosts
  • Global Variables: Apply to entire inventory
  • Vault Variables: Encrypted sensitive data

Execution History

The Executions tab shows all Ansible runs.

Execution List

Each execution shows:

  • Execution ID
  • Playbook name
  • Start time and duration
  • Status (Running, Success, Failed)
  • User who initiated
  • Affected hosts

Execution Details

Click on an execution to view:

Summary

  • Total hosts targeted
  • Successful/failed/unreachable
  • Tasks executed
  • Changes made
  • Execution time

Output

  • Real-time streaming output
  • Color-coded by status
  • Task-by-task breakdown
  • Error messages highlighted
  • Searchable logs

Host Results

  • Per-host status
  • Changed tasks
  • Failed tasks
  • Skipped tasks
  • Fact gathering results

Artifacts

  • Generated files
  • Reports
  • Logs
  • Configuration backups

Re-running Executions

  1. Click Re-run on execution
  2. Modify parameters if needed
  3. Execute again

Scheduling

Schedule playbook executions:

  1. Click Schedule on playbook
  2. Configure:
    • Frequency: Once, Daily, Weekly, Monthly
    • Time: Execution time
    • Parameters: Variables and options
    • Notifications: Email on completion
  3. Click Create Schedule

Ad-hoc Commands

Execute quick commands without playbooks:

  1. Click Ad-hoc Command
  2. Select:
    • Target hosts/groups
    • Module to use
    • Module arguments
    • Execution options
  3. Click Run

Common ad-hoc uses:

  • Ping connectivity test
  • Gather facts
  • Copy files
  • Restart services
  • Install packages
  • Check disk space

Best Practices

Playbook Design

  1. Idempotency: Ensure playbooks can run multiple times
  2. Error Handling: Use blocks and rescue
  3. Variable Usage: Parameterize for flexibility
  4. Role-Based: Organize into reusable roles
  5. Documentation: Comment complex tasks

Security

  1. Vault Usage: Encrypt sensitive data
  2. Key Management: Use SSH keys, not passwords
  3. Least Privilege: Minimize sudo usage
  4. Audit Trail: Log all executions
  5. Input Validation: Sanitize user inputs

Performance

  1. Parallel Execution: Adjust forks appropriately
  2. Fact Caching: Cache facts when possible
  3. Pipelining: Enable SSH pipelining
  4. Async Tasks: Use async for long operations
  5. Conditional Execution: Skip unnecessary tasks

Troubleshooting

Connection Issues

  • Verify SSH connectivity
  • Check SSH keys/passwords
  • Ensure Python installed on target
  • Verify ansible_user is correct
  • Check firewall rules

Playbook Failures

  • Review error messages
  • Check syntax with ansible-playbook --syntax-check
  • Verify variables are defined
  • Test with increased verbosity (-vvv)
  • Check module documentation

Performance Problems

  • Increase forks for parallelism
  • Enable fact caching
  • Use async for long tasks
  • Optimize gathering facts
  • Consider push vs pull mode

Variable Issues

  • Check variable precedence
  • Verify variable names
  • Review group_vars/host_vars
  • Check for typos
  • Use debug module to inspect

Integration with Vapor

System Integration

Vapor can generate Ansible inventory from:

  • Docker containers
  • Virtual machines
  • Kubernetes nodes
  • Network devices

Workflow Automation

Combine Vapor features:

  1. Create VMs with Vapor
  2. Auto-generate inventory
  3. Run configuration playbooks
  4. Monitor with Vapor metrics

API Integration

Use Vapor API for automation:

python
# Example: Trigger playbook via API
import requests

response = requests.post(
    "http://vapor/api/v1/ansible/playbooks/execute",
    json={
        "playbook": "webserver.yml",
        "inventory": "production",
        "extra_vars": {"version": "1.2.3"}
    },
    headers={"Authorization": "Bearer TOKEN"}
)

Dibuat dengan semangat gotong royong demi kemajuan bangsa 🇮🇩