Playbooks against Remote Hosts
Connect to remote Linux and Windows hosts using Ansible playbooks.
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:
Press + to interact
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:
- Create a
ping.yml
file. - Add the
hosts
line to use the host pattern ofall
.
Press + to interact
---- hosts: all
- Create a
vars
list and define the connection variables. Replace<Password>
with your password.
Press + to interact
vars:ansible_user: ansibleansible_password: <Password>ansible_ssh_common_args: '-o StrictHostKeyChecking=no'
Defining the variables in the playbooks ...