Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ansible lookup pipe what does this pipe means?

Tags:

ansible

In ansible, I can use something like:

debug:var="{{lookup('pipe', 'date +%Y%m%d')}}"

This can work, but what does the 'pipe' mean? cannot find any detail explanation for this in ansible document, want to understand what happens when this statement run.

For example, is the 'date' means run 'date' command from shell? and then use pipe-like way to format the date in the specified way?

like image 521
Jakim Avatar asked Sep 18 '16 05:09

Jakim


People also ask

What does lookup do in Ansible?

Lookup plugins retrieve data from outside sources such as files, databases, key/value stores, APIs, and other services. Like all templating, lookups execute and are evaluated on the Ansible control machine. Ansible makes the data returned by a lookup plugin available using the standard templating system.

What is Ansible playbook command?

Ansible Playbooks are lists of tasks that automatically execute against hosts. Groups of hosts form your Ansible inventory. Each module within an Ansible Playbook performs a specific task. Each module contains metadata that determines when and where a task is executed, as well as which user executes it.


1 Answers

The pipe is an ansible lookup plugin that will calculate the output of the shell command you specify in lookup's second parameter, and pipe it to the left side of your lookup. You can specify any shell command there.

Therefore in your example, the output of shell command date +%Y%m%d should be pipe'd to the debug module and var should be set to this output value.

I generally use pipe lookup to set a fact for timestamp so that I can append timestamp in a variable at the end for any resource names, like this:

- set_fact: timestamp="{{ lookup('pipe', 'date +%Y%m%d%H%M%S') }}"

Official documentation on Lookups, and specific example that includes pipe.

like image 185
rk2 Avatar answered Jan 03 '23 15:01

rk2