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 "