Over a million developers have joined DZone.

A Read-Eval-Print Loop for Ansible

DZone's Guide to

A Read-Eval-Print Loop for Ansible

Did you know that Ansible has a REPL tool available that can help you out with your Ansible coding? It helps you quickly check out the syntax of an API or test an idea.

· DevOps Zone ·
Free Resource

Download the blueprint that can take a company of any maturity level all the way up to enterprise-scale continuous delivery using a combination of Automic Release Automation, Automic’s 20+ years of business automation experience, and the proven tools and practices the company is already leveraging.

One must-have tool for any language is the availability of a REPL to quickly check out the syntax of an API or test out an idea really quickly. Ansible is no different, especially since sometimes, you might have a very long running playbook and it may be difficult to wait for it to run before discovering you had the syntax for something off at the end.

Ansible's Lesser-Known Read-Eval-Print Loop Tool

Luckily, Ansible comes with the lesser known ansible-console command. You can use this to execute any one of the modules included in ansible to roughly test something out and can run it against a local or remote host.

vagrant @monitor: ~$ ansible - console localhost[WARNING]: Host file not found: /etc/ansible / hosts

 [WARNING]: provided hosts list is empty, only localhost is available

Welcome to the ansible console.
Type help or ? to list commands.

vagrant @localhost(1)[f: 5] $ setup

# very long json of facts omitted

vagrant @localhost(1)[f: 5] $ debug msg = ”distribution version reversed
is {
  ansible_distribution_version | reverse
localhost | SUCCESS => {“
 msg”: “distribution version reversed is 40.41”

You can run ad-hoc commands on the machine through it, as well.

vagrant@localhost (1)[f:5]$ ls /tmplocalhost | SUCCESS | rc=0 >>ansible_busvWCvagrant-ansiblevagrant-shell

This also doubles as an easy and cheap REPL for Jinja2, as well, if you need to test some Jinja2 syntax out.

Download the ‘Practical Blueprint to Continuous Delivery’ to learn how Automic Release Automation can help you begin or continue your company’s digital transformation.

console ,repl ,ansible ,devops

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}