ansible first playbook
We can use ansible playbook to help us automate many of the common tasks. In this example, we going to make use of our inventory.ini file we configured earlier and then
In our first playbook, we're just going to install apache web server on the target machine. So we're using the following playbook:-
---
- hosts: all
become: true
tasks:
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/apt_module.html
- name: Install apache httpd
ansible.builtin.apt:
name: apache2
state: present
update_cache: yes
# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#examples
# - name: Copy file with owner and permissions
# ansible.builtin.copy:
# src: index.html
# dest: /var/www/html
# owner: root
# group: root
# mode: '0644'
Next we are going to run the following command
ansible-playbook -i inventory.ini first-playbook.yaml
And we should have the following configured for us:-
Now it is time to explore thousands of playbook in ansible.
Ansible Galaxy
Ansible galaxy is a marketplace that allow us to use other playbooks. In this example, we are going to setup docker on our machine.
First we need to install by running this command:-
ansible-galaxy role install bsmeding.docker
Comments