Skip to content

필사 모드: Ansible-Runner (Running Ansible from Python)

English
0%
정확도 0%
💡 왼쪽 원문을 읽으면서 오른쪽에 따라 써보세요. Tab 키로 힌트를 받을 수 있습니다.
원문 렌더가 준비되기 전까지 텍스트 가이드로 표시합니다.

Overview

I wanted to use dynamic inventories and dynamic variables in Django, which runs as Python code, and fortunately I found a module called [ansible-runner](https://ansible-runner.readthedocs.io/en/stable/). Ansible Runner is a Python module that enables running Ansible from Python. Upon trying it, I found it also has features that guarantee consistent execution results regardless of the ansible version being used, and it was convenient for registering event callbacks to output results in real-time. Detailed documentation is available on the [official website](https://ansible-runner.readthedocs.io/en/stable/).

How to Run

As shown below, after importing ansible_runner, you can execute an ansible playbook by calling run with `private_data_dir`, `playbook`, and `inventory` as arguments.

Of course, ansible must be installed on the server running ansible-runner. I installed it using pip as follows: `pip install ansible`

def event_callback(event_data):

do something every event

print(event_data)

def finished_callback(runner):

#do something after finishing

print runner

return

r = ansible_runner.run(

private_data_dir=os.path.join(

settings.BASE_DIR,"private_directory"

),

playbook=os.path.join(

settings.BASE_DIR,"playbook_directory",

"setup.yml"

),

event_handler=event_callback,

finished_callback=finished_callback,

quiet=True,

)

Any playbook that can be executed in ansible can also be executed through `ansible_runner`.

Quiz

Q1: What is the main topic covered in "Ansible-Runner (Running Ansible from Python)"?

Learn about the Ansible Runner module that enables running Ansible from Python.

As shown below, after importing ansible_runner, you can execute an ansible playbook by calling run

with private_data_dir, playbook, and inventory as arguments. Of course, ansible must be installed

on the server running ansible-runner.

현재 단락 (1/26)

I wanted to use dynamic inventories and dynamic variables in Django, which runs as Python code, and ...

작성 글자: 0원문 글자: 1,630작성 단락: 0/26