Ansible plugins 기능은 Ansible playbook 작성할 때 modules 만큼 중요합니다. Ansible plugins이 무엇인지 한번 살펴보겠습니다.
Ansible plugins ?
Ansible document에 따르면 Ansible plugins은 “Ansible의 core functionality를 강화하기 위한 코드 모음이며 Ansible은 plugin architecture를 이용하여 풍부하고, 유연하며 확장 가능한 기능 셋을 활성화합니다” 라고 되어 있습니다.
Plugins are pieces of code that augment Ansible’s core functionality. Ansible uses a plugin architecture to enable a rich, flexible and expandable feature set.
따라서, 플러그인은 앤서블이 잘 실행될 수 있도록 도와주는 기능이라고 생각하면 될 것 같습니다.
이것 만으로는 잘 이해가 되지 않습니다.
그래서 이 플러그인이 도대체 어떤 식으로 앤서블의 실행을 도와 주는지 확인하기 위해, 앤서블에서 제공하는 플러그인이 무엇이 있는지 알아보겠습니다.
Ansible plugins 종류
Ansible 2.9버전 기준 Ansible document를 살펴보면 Ansible core에 포함되어 제공되는 다양한 plugins의 목록을 확인할 수 있습니다. 이 내용을 조금 보다 보면 “Become, Inventory, Lookup, Vars, Filters”같이 눈에 띄는 이름들이 보이실 겁니다.
그렇습니다, plugins은 바로 모듈처럼 관리 대상 노드에 직접적인 작업을 실행하진 않지만 이미 우리가 사용하고 있는 “인벤토리, 변수, Become”같이 앤서블 실행에 필요한 기능들을 말하는 것이란 걸 확인할 수 있습니다.
아래 그림의 각각의 이름들은 plugins 타입을 나타내는 것이며 하나의 타입 안에는 여러 개의 plugins들이 존재합니다.

예를 들어 위 그림의 목록에 있는 Become Plugins 타입에는 아래 그림과 같은 plugins이 또 존재합니다.

Ansible plugins 도움말 보기
Ansible plugins 기능도 모듈과 같이 ansible-doc 명령을 이용하여 도움말을 볼 수 있습니다.
“ansible-doc -h” 명령을 실행해 보면 -t 부분에서 plugins 타입을 입력할 수 있는 항목이 나옵니다.
# ansible-doc -h
...
-t {become,cache,callback,cliconf,connection,httpapi,inventory,lookup,netconf,shell,module,strategy,vars}, --type {become,cache,callback,cliconf,connection,httpapi,inventory,lookup,netconf,shell,module,strategy,vars}
Choose which plugin type (defaults to "module").
Available plugin types are : ('become', 'cache',
'callback', 'cliconf', 'connection', 'httpapi',
'inventory', 'lookup', 'netconf', 'shell', 'module',
'strategy', 'vars')
..
“-t <플러그인 타입>” 옵션을 이용하여 플러그인 타입을 기재해 주고 “-l (리스트)” 옵션을 추가하면 지정된 플러그인 타입이 제공하는 목록을 확인해 보실 수 있습니다.
# ansible-doc -t inventory -l
nmap Uses nmap to find hosts to target
host_list Parses a 'host list' string
hcloud Ansible dynamic inventory plugin for the Hetzner Cloud
openstack OpenStack inventory source
vultr Vultr inventory source
aws_ec2 EC2 inventory source
cloudscale cloudscale.ch inventory source
virtualbox virtualbox inventory source
constructed Uses Jinja2 to construct vars and groups based on existing inventory
...
이렇게 해서 “inventory” 플러그인 타입에서 제공하는 “aws_ec2” 플러그인은 어떻게 사용해야 되는것인지 도움말을 확인할 수 있습니다.
# ansible-doc -t inventory aws_ec2
> AWS_EC2 (/usr/lib/python2.7/site-packages/ansible/plugins/inventory/aws_ec2.py)
Get inventory hosts from Amazon Web Services EC2. Uses a YAML configuration file that ends with `aws_ec2.(yml|yaml').
* This module is maintained by The Ansible Community
OPTIONS (= is mandatory):
- aws_access_key
The AWS access key to use.
(Aliases: aws_access_key_id)[Default: (null)]
set_via:
env:
- name: EC2_ACCESS_KEY
- name: AWS_ACCESS_KEY
- name: AWS_ACCESS_KEY_ID
...
마치며
우리는 우리도 모르게 Ansible plugins 기능을 사용하고 있었으며, Ansible의 기능들은 plugins을 통해서 제공되는 것을 엿볼 수 있었습니다. 따라서 Ansible은 새로운 plugins의 추가 또는 plugins 기능 업데이트를 통하여 성능을 강화시켜 나가는 것으로 확인됩니다. plugins 종류는 하나하나 확인해 보기 힘들 정도로 너무나도 많습니다. 나에게 필요한 것부터 하나씩 찾아서 사용해 보는 게 좋은 방법일 것입니다.
다음 포스팅에서는 plugins을 직접 활용해 보는 예제를 진행해 보도록 하겠습니다.
참고사이트
Ansible 공식 홈페이지 : https://docs.ansible.com/ansible/latest/plugins/plugins.html