Search icon CANCEL
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
Hands-On Enterprise Automation with Python

You're reading from   Hands-On Enterprise Automation with Python Automate common administrative and security tasks with Python

Arrow left icon
Product type Paperback
Published in Jun 2018
Publisher Packt
ISBN-13 9781788998512
Length 398 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Bassem Aly Bassem Aly
Author Profile Icon Bassem Aly
Bassem Aly
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Setting Up Our Python Environment 2. Common Libraries Used in Automation FREE CHAPTER 3. Setting Up the Network Lab Environment 4. Using Python to Manage Network Devices 5. Extracting Useful Data from Network Devices 6. Configuration Generator with Python and Jinja2 7. Parallel Execution of Python Script 8. Preparing a Lab Environment 9. Using the Subprocess Module 10. Running System Administration Tasks with Fabric 11. Generating System Reports and System Monitoring 12. Interacting with the Database 13. Ansible for System Administration 14. Creating and Managing VMware Virtual Machines 15. Interacting with the OpenStack API 16. Automating AWS with Boto3 17. Using the Scapy Framework 18. Building a Network Scanner Using Python 19. Other Books You May Enjoy

Using Ansible in ad hoc mode

Ansible ad hoc mode is used when you need to execute simple operations on remote machines, without creating complex and persistent tasks. This is where a user usually starts when they first work on Ansible, before performing advanced tasks in a playbook.

Executing the ad-hoc command requires two things. First, you will need the host or group from the inventory file; secondly, you will need the Ansible module that you want to execute towards the target machine:

  1. First, let's define our hosts and add the CentOS and Ubuntu machines in a separate group:
[all:children]
centos-servers
ubuntu-servers

[centos-servers]
centos-machine01 Ansible_ssh_host=10.10.10.193

[ubuntu-servers]
ubuntu-machine01 Ansible_ssh_host=10.10.10.140

[all:vars]
Ansible_ssh_user=root
Ansible_ssh_pass=access123

[centos-servers:vars]
Ansible_ssh_user=root
Ansible_ssh_pass=access123

[ubuntu...
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