Search⌘ K
AI Features

Playbooks against Remote Hosts

Explore how to transform ad-hoc Ansible commands into reusable playbooks that connect to remote Linux and Windows hosts. Practice creating playbooks with variables and prompts to enhance security and repeatability, preparing you to manage remote infrastructure confidently.

Let’s look at how you can codify the ad-hoc command to connect to the Linux instance or virtual machine.

Connect to remote Linux host

You will learn how to convert the following ad-hoc command to an Ansible playbook:

Shell
ansible all -i <Public Ip Address>, -m ping \
-e "ansible_user=ansible ansible_password=<Password> ansible_ssh_common_args='-o StrictHostKeyChecking=no'"

Create the playbook

Create the playbook in these steps:

  1. Create a ping.yml file.
  2. Add the hosts line to use the host pattern of all.
YAML
---
- hosts: all
  1. Create a vars list and define the connection variables. Replace <Password> with your password.
YAML
vars:
ansible_user: ansible
ansible_password: <Password>
ansible_ssh_common_args: '-o StrictHostKeyChecking=no'

Defining the variables in the playbooks prevents you from defining them at run time. ...