ansible lookup
时间: 2023-09-25 21:13:27 浏览: 134
ansible快速了解
Ansible lookup plugins allow you to query external data sources or perform simple calculations within your Ansible playbooks. These plugins provide a way to dynamically retrieve information during playbook execution.
Here's an example of using the `lookup` plugin in Ansible:
```yaml
- name: Retrieve data from a file
debug:
msg: "{{ lookup('file', '/path/to/file.txt') }}"
- name: Retrieve data from a command output
shell: echo "Hello, World!"
register: command_output
- name: Display the command output
debug:
var: command_output.stdout_lines | lookup('first')
```
In the above example, the `lookup` plugin is used to read the contents of a file (`file.txt`) and display it using the `debug` module. It is also used to extract the first item from the `stdout_lines` of a command execution result.
You can find more information about available lookup plugins in the Ansible documentation.
阅读全文