Basic playbooks that automate the provisioning of systems

Basic playbooks that automate the provisioning of systems


Ansible allows you to automate and organize system configuration tasks for more than one asset at a time. It is only necessary to install a set of packages on the server that will be the controller and have SSH access to the client machines.
In this entry we will see how to build “playbooks” that are the way Ansible creates automated scripts to configure computers. Let’s assume that we have an Ansible configured server and some clients.
Playbooks are a way to send commands to remote computers via scripts instead of using commands individually. These playbooks are written in YAML format. Each contains one or more “plays” that are assigned to teams to take action.

Exploring a basic playbook

Let’s look at a basic playbook:

- hosts: Incubator
 user: telans
 sudo: true
 - name: Witness copy file
 action: copy src=/home/ubuntu/playbooks/basic/testfile dest=/tmp/testfile owner=telans group=telans mode=0644

The first line is a requirement of the YAML syntax, the second refers to the computers on which the playbook, “Incubator” will be applied on a tab inside the /etc/ansible/hosts file.
Then comes the task; which has an identifiable name and in our case is “Witness copy file”, the next key is “copy” and refers to the Ansible module to be used, in this case that allows copying files; Each key respects a particular syntax. Here is the reference to the copying module:

Once we have built the playbook it runs as follows.

ansible-playbook playbook.yml


Note that execution is performed on computers of different operating systems; in this case, Ubuntu and Red Hat Linux.

Other example playbooks

Ubuntu operating system update

- hosts: NewHosts
 user: telans
 sudo: true

 - name: updates a server
 apt: update_cache=yes
 - name: upgrade a server
 apt: upgrade=full
 - name: upgrade distro
 apt: upgrade=dist

Running a “ping” command on a Windows server

- name: Ping
 hosts: Windows
 gather_facts: false
 ansible_ssh_user: uniqs
 ansible_ssh_pass: uniqs
 ansible_ssh_port: 5986
 ansible_connection: winrm

 - name: ping

With Ansible you can automate simple or complex tasks. These are basic examples of how to start building your playbooks. In an upcoming blog post we’ll talk about how to implement playbooks


By Uniqs


Dejá un comentario

Tu dirección de correo electrónico no será publicada. Los campos necesarios están marcados *