DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. A Read-Eval-Print Loop for Ansible

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.

James Carr user avatar by
James Carr
·
Feb. 24, 17 · Opinion
Like (1)
Save
Tweet
Share
4.87K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Ansible (software)

Published at DZone with permission of James Carr, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • OpenID Connect Flows
  • Key Considerations When Implementing Virtual Kubernetes Clusters
  • Distributed SQL: An Alternative to Database Sharding
  • How To Use Terraform to Provision an AWS EC2 Instance

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: