Ansible_playbook_lookup組件


#
# Topic: Ansible lookups組件
# State:
# 1. 通過lookups組件,Ansible可以從其他地方拉取數(shù)據(jù)
# 2
# Testing environment:
# OS: RHEL6.6
# Python: python2.7.5
# Ansible: ansible 2.3.1.0
# Nodes: 3
#

    1. lookups file:
    • 原理:
      利用python codecs.open模塊打開一個(gè)文件并返回文件內(nèi)容
    • 用法:
      可以將返回的結(jié)果放在一個(gè)變量中,然后使用python的字符串處理方法進(jìn)行處理
    • 示例:

# lookups file

  • name: lookups file
    remote_user: root
    hosts: tomcat
    gather_facts: no
    tasks:

    • name: lookups file
      vars:
      user: "{{ lookup('file', '/etc/ansible/looksup/looks.yml') }}"
      debug: msg="{% for i in user.split("\n") %}{{i}}{% endfor %}"
    1. lookups password:
    • 原理:
      對獲取的內(nèi)容進(jìn)行加密處理
    • 用法:
      lookup('password', 'file_path')
    • 示例:

# lookups file

  • name: lookups file
    remote_user: root
    hosts: tomcat
    gather_facts: no
    tasks:

    • name: lookups file
      vars:
      user: "{{ lookup('password', '/etc/ansible/looksup/looks.yml') }}"
      debug: msg="{{user}}"
    1. lookups pipe:
    • 原理:
      相當(dāng)于linux中的管道的作用, 將一個(gè)命令輸出結(jié)果返回
    • 用法:
      lookup('pipe', 'command')
    • 示例:

  • hosts: tomcat
    gather_facts: no
    tasks:

    • name: the first task
      vars:
      content: "{{ lookup('pipe', 'date +%y-%m-%d') }}"
      debug: msg="{% for i in content.split("\n") %} {{ i }} {% endfor %}"
    1. lookups redis_kv:
    • 原理:
      鏈接redis數(shù)據(jù)庫, 從redis中獲取數(shù)據(jù)

    • 用法:

    • 示例:

    1. lookups template:
    • 原理:
      先渲染jinja2模板之后再讀取文件內(nèi)容

    • 用法:

    • 示例:


  • hosts: tomcat
    remote_user: root
    tasks:
    • name: first
      vars:
      content: "{{lookup('template', './tmp.j2')}}"
      debug: msg="{% for i in content.split("\n") %} {{i}} {% endfor %}"
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 一.ansible (1) ansible: ansible是一款新出現(xiàn)的自動化運(yùn)維系統(tǒng),基于python開發(fā)并集...
    楠人幫閱讀 2,142評論 0 8
  • # Topic: Ansible playbook中的循環(huán)# State:# 1. 通過使用循環(huán)可以讓重復(fù)的工...
    Michael_林閱讀 1,839評論 0 0
  • ansible 系統(tǒng)架構(gòu) ansible簡介ansible是新出現(xiàn)的自動化運(yùn)維工具,ansible是一個(gè)配置管理和...
    運(yùn)維阿文閱讀 9,853評論 1 53
  • Ansible簡介 Ansible是2013年推出的一款I(lǐng)T自動化和DevOps軟件,目前由Redhat已簽署An...
    魏鎮(zhèn)坪閱讀 2,450評論 1 6
  • 今天和小樂一起去參加奧賽組織的親子制作月餅活動還有親子比賽項(xiàng)目。 月餅做好之后,趁著烤制的空檔舉行了親子運(yùn)動項(xiàng)目。...
    一瓶花開閱讀 407評論 0 5

友情鏈接更多精彩內(nèi)容