Skip to content

The custom Ansible strategy module inherits from the Ansible strategy class, enabling task-level control.

Notifications You must be signed in to change notification settings

chungeun-choi/control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview 🙌🏻

❗This example works correctly with the versions listed below. (Other versions have not been tested.)❗

Component Version
Python version 3.10
Ansible core 2.12
Ansible package (collection) 5.0.0


This document provides an example of how to execute a custom Ansible strategy module. The custom strategy module, Control, is not a command-line tool but an Ansible object (Python code) designed for asynchronous playbook execution.

This repository includes a FastAPI-based application (web service) that enables the execution of the developed Control strategy module. The execution structure is as follows.

img.png

Quick start

1. Create Docker Containers

The working directory is example/docker. (Navigate to the directory before proceeding)

  • Run the docker-compose.yml file in the directory:

    ! docker-compose up -d

2. SSH Key Exchange

  • Generate SSH key (if the key does not exist in the local environment)

    ! ssh-keygen
  • Copy SSH key

    # The port numbers for the containers are 220 (vm1) and 221 (vm2). The password is 'test1234'.
    ! ssh-copy-id -p 220 root@localhost
    ! ssh-copy-id -p 221 root@localhost
  • Verify container access

    ! ssh -p 220 root@localhost # Verify successful connection
    ! ssh -p 221 root@localhost # Verify successful connection

3. Run the Application (Web Service)

The working directory is the project root (./). (Navigate to the directory before proceeding)

  • Create python virtual environment

    # for mac 
    ! python -m venv .venv
    ! source ./.venv/bin/activate
    
    # for window
    ! python -m venv .venv
    ! .venv\Scripts\activate
  • Install Dependency Modules

    pip install -r requirements.txt
  • Execute the main.py function.

    python main.py
  • Access localhost:8080/docs to verify. img.png

4. How to Control Using Example Ansible and API

The playbook written as an example is located in example/playbook.

  • Run the playbook through localhost:8080/playbook/run

    // Request body example for execution
    {
      "playbook": [
        "./example/playbook/playbook.yml"
      ],
      "inventory": "./example/playbook/inventory.ini",
      "passwords": {}
    }
    

    img.png

  • Check the logs from the running application and verify the playbook_id received in the API response

    img.png

  • Use playbook_id to control via API

    img.png

About

The custom Ansible strategy module inherits from the Ansible strategy class, enabling task-level control.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published