기타

ansible library 확장

세모데 2019. 9. 13. 16:47

python으로 custom library확장하고 싶을 경우 아래와 같이 작성하여 반영

 

1. lib program 작성 (custom_python_lib1.py)

 

import requests

import json

 

url= 'http://10.10.10.10/test'

user='test'

passwd='test'

s_headers={'content-type':'application/json'}

s_reponse = requests.post(url, data='test', headers=s_headers,

                    auth=(user,passwd)).json

 

2. playbook안에 library 디렉토리 생성

 mkdir library

 cd library

 cp custom_python_lib1.py .

 

 

3.  playbook 작성

---

- name:  test

   hosts: localhost

   gather_facts: false

   connection: local

   

   tasks:

      - name : test1

         action: custom_python_lib1

         register: result

 

      - debug:

         var: result

 

4. 수행

    ansible-playbook test.yml