Skip to Content
Practical Ansible 2
book

Practical Ansible 2

by Daniel Oh, James Freeman, Fabio Alessandro Locati
June 2020
Intermediate to advanced content levelIntermediate to advanced
410 pages
9h 52m
English
Packt Publishing
Content preview from Practical Ansible 2

Limiting the host's execution

While testing a playbook, it might make sense to test on a restricted number of machines; for instance, just one. Let's get started:

  1. To use the limitation of target hosts on Ansible, we will need a playbook. Create a playbook called helloworld.yaml that contains the following content:
---- hosts: all  tasks:    - debug:        msg: "Hello, World!"
  1. We also need to create an inventory with at least two hosts. In my case, I created a file called inventory that contains the following content:
[hosts]host1.example.comhost2.example.comhost3.example.com

Let's run the playbook in the usual way with the following command:

$ ansible-playbook -i inventory helloworld.yaml

By doing this, we will receive the following output:

PLAY ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Ansible - Third Edition

Mastering Ansible - Third Edition

James Freeman, Jesse Keating
Security Automation with Ansible 2

Security Automation with Ansible 2

Akash Mahajan, MADHU AKULA

Publisher Resources

ISBN: 9781789807462Supplemental Content