티스토리 뷰

엔지니어링

Ansible 커스텀 모듈 개발

warpmemory 2020. 2. 26. 18:15

커스텀 모듈 - testing.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/env python
 
from ansible.module_utils.basic import *
import os, json
import re, sys
 
def firstProg(text):
  text1 = "Hello " + text
  return text1
 
if __name__ == '__main__':
  fields = {
      "yourName": {"required": True, "type""str"}
  }
  module = AnsibleModule(argument_spec=fields)
  yourName = os.path.expanduser(module.params['yourName'])
  newName = firstProg(yourName)
  module.exit_json(msg=newName)
cs

플레이북 - main.yaml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
- hosts: all
  remote_user: root
  gather_facts: yes
 
  vars_prompt:
   - name: giveName
     prompt: "Please provide your name"
     private: no
     failed_when: giveName is undefined
 
 tasks:
  - name: Python Execution
    testing: yourName={{ giveName }}
    register: result
  - debug: var=result
cs

실행

ansible-playbook main.yaml
 

Create a custom module with Ansible-Python

Ansible modules

medium.com

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
페이지
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함