Ansible's Lookup plugin

Source: Internet
Author: User
Tags redis etcd

The lookup plugin for ansible can be used to read information from external data and then pay a variable. The types of external data information obtained include reading the contents of a file, randomly generating password, executing shell commands, reading Redis key values, and so on. Note that all of the operations of lookup are done on the Ansible console, not on the remote target machine.

Example:

----hosts:test_server remote_user:root tasks:-Name: Get normal file content (files are present on the Ansible console) debug:msg= "the contests is {lookup (' file ', '/tmp/foo.txt ')}} "-Name: Gets the contents of the User field under the [production] block in the Users.ini file debug:msg=" The contests I s {{lookup (' ini ', ' User Section=production File=users.ini ')}} "-Name: Get ENV environment variable debug:msg=" PATH env is | {{lookup (' env ', ' PATH ')}} "-Name: Execute shell command debug:msg=" Exec hostname cmd | {{lookup (' pipe ', ' hostname ')}} '-name: randomly generated password. The default is 20-bit, can also be specified, such as length=15 debug:msg= "PASSWORD is {{lookup (' PASSWORD ', '/tmp/test_lookup_password_ ' + ' {{Inventory_ hostname}} ')}} "-Name: Query Redis key value, need to install Python Redis package debug:msg=" {{lookup (' redis_kv ', ' redis://localhost:6379,some  Key ')} is the value in the Redis for Somekey "-Name: Query Etcd key value debug:msg=" {{lookup (' Etcd ', ' foo ')}} is a value from a Locally running Etcd "-Name: Get template debug:msg=" {{lookup (' template ', './some_template.j2 ')}} is a value fro M Evaluation OF This template "
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.