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


Then we will create our playbook which looks like this:

---
- hosts: all
  become: true
  roles:
    - bsmeding.docker

And let's run our playbook using the following command

 ansible-playbook -i inventory.ini docker-playbook.yaml

The outputs of the playbook:


And if I ssh into my vm, then i should be able to run docker.




Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type