Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Ansible 2 Cloud Automation Cookbook

You're reading from   Ansible 2 Cloud Automation Cookbook Write Ansible playbooks for AWS, Google Cloud, Microsoft Azure, and OpenStack

Arrow left icon
Product type Paperback
Published in Feb 2018
Publisher Packt
ISBN-13 9781788295826
Length 200 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Aditya Patawari Aditya Patawari
Author Profile Icon Aditya Patawari
Aditya Patawari
Vikas Aggarwal Vikas Aggarwal
Author Profile Icon Vikas Aggarwal
Vikas Aggarwal
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Getting Started with Ansible and Cloud Management 2. Using Ansible to Manage AWS EC2 FREE CHAPTER 3. Managing Amazon Web Services with Ansible 4. Exploring Google Cloud Platform with Ansible 5. Building Infrastructure with Microsoft Azure and Ansible 6. Working with DigitalOcean and Ansible 7. Running Containers with Docker and Ansible 8. Diving into OpenStack with Ansible 9. Ansible Tower 10. Other Books You May Enjoy

Executing playbooks locally

Most of the time, during the course of this book, our playbooks will be running locally and interacting with a cloud provider. The cloud provider, usually, exposes an API over HTTPS. Generally, we need an inventory file, which has a record of all the hosts, for Ansible to run the playbooks. Let us try to work around it.

The easiest way of running a playbook locally is by using the keyword localhost in the playbook as a value for the hosts key. This will save us from creating and managing the inventory file altogether.

How to do it...

Consider the following playbook which we can execute without an inventory:

---
- hosts: localhost
tasks:
- name: get value
debug:
msg: "The value is: secret-value"

To execute this, we can just run the ansible-playbook command with this playbook:

$ ansible-playbook playbook.yml
[WARNING]: Host file not found: /etc/ansible/hosts
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [include secret] **********************************************************
ok: [localhost]
TASK [get value] ***************************************************************
ok: [localhost] => {
"msg": "The value is: secret-value"
}
PLAY RECAP *********************************************************************
localhost : ok=3 changed=0 unreachable=0 failed=0
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime