Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can ansible-playbook read from stdin instead of a file?

Tags:

ansible

Is it possible for ansible-playbook to read a playbook from the standard input? I thought maybe dash (-) would be a way to specify stdin, like it does in the cat command and I tried:

$ ansible-playbook -

But it fails with:

ERROR! the playbook: - could not be found
like image 710
singuliere Avatar asked Jan 20 '19 09:01

singuliere


People also ask

Which format does an Ansible playbook use?

Creating and Running your First Ansible Playbook. Playbooks use the YAML format to define one or more plays. A play is a set of ordered tasks that are arranged in a way to automate a process, such as setting up a web server or deploying an application to production. In a playbook file, plays are defined as a YAML list.

How do you take input from playbook?

If you want your playbook to prompt the user for certain input, add a 'vars_prompt' section. Prompting the user for variables lets you avoid recording sensitive data like passwords.

Can we use conditionals in playbook?

You can use conditionals with re-usable tasks files, playbooks, or roles.

What is the difference between Ansible module and playbook?

Ansible modules are standalone scripts that can be used inside an Ansible playbook. A playbook consists of a play, and a play consists of tasks. These concepts may seem confusing if you're new to Ansible, but as you begin writing and working more with playbooks, they will become familiar.


1 Answers

The thing you are looking for is /dev/stdin, which acts like a file but, as its name implies, is the stdin of the current process.

$ ansible-playbook -i localhost, -c local /dev/stdin <<'FOO'
- hosts: all
  tasks:
  - debug: msg="hello from stdin"
FOO
PLAY [all] *********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [debug] *******************************************************************
ok: [localhost] =>
  msg: hello from stdin
like image 55
mdaniel Avatar answered Nov 14 '22 18:11

mdaniel