Ansible

Ansible - My First Playbook

  1. Write a playbook that will: a. Install the package zlib b. Create the file /tmp/some_file
  2. Run the playbook on a remote host

Difficulty: unrated

Source: bregman-arie/devops-exercises by Arie Bregman

Answer

  1. vi first_playbook.yml
- name: Install zlib and create a file
  hosts: some_remote_host
  tasks:
    - name: Install zlib
      package:
        name: zlib
        state: present
      become: yes
    - name: Create the file /tmp/some_file
      file:
        path: '/tmp/some_file'
        state: touch
  1. First, edit the inventory file: vi /etc/ansible/hosts
[some_remote_host]
some.remoted.host.com

Run the playbook

ansible-playbook first_playbook.yml