DevOps Classroom notes 03/Nov/2026

Ansible Playbook

WOW – Way of working:

  • we need find out manual steps what work need to do
  • ensure manual commands need to work
  • create yaml playbook for Activity
sudo apt update && sudo apt install apache2 -y 
sudo apt install wget unzip -y 
#  https://templatemo.com/
cd /tmp
sudo wget https://templatemo.com/tm-zip-files-2020/templatemo_586_scholar.zip
sudo unzip templatemo_586_scholar.zip
sudo cp -rf templatemo_586_scholar/* /var/www/html/
sudo rm -rf /tmp/templatemo_586_scholar /tmp/templatemo_586_scholar.zip
sudo systemctl restart apache2 
sudo systemctl enable apache2 

Create new ubuntu

  1. install ansible
  2. created ssh-keygen
  3. cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
```yaml
---
- name: "Scholar Website"
  hosts: all
  become: yes

  tasks:
    - name: "Install wget and unzip"
      ansible.builtin.apt:
        name:
          - wget
          - unzip
        state: present
        update_cache: yes

    - name: "Install Apache2"
      ansible.builtin.apt:
        name: apache2
        state: present

    - name: "Download website template"
      ansible.builtin.get_url:
        url: "https://templatemo.com/tm-zip-files-2020/templatemo_586_scholar.zip"
        dest: /tmp/templatemo_586_scholar.zip
        mode: '0644'

    - name: "Unzip website template"
      ansible.builtin.unarchive:
        src: /tmp/templatemo_586_scholar.zip
        dest: /tmp/
        remote_src: yes

    - name: "Ensure Apache document root exists"
      ansible.builtin.file:
        path: /var/www/html
        state: directory
        owner: www-data
        group: www-data
        mode: '0755'

    - name: "Copy website files to Apache document root"
      ansible.builtin.copy:
        src: /tmp/templatemo_586_scholar/
        dest: /var/www/html/
        remote_src: yes
        owner: www-data
        group: www-data
        mode: preserve

    - name: "Restart and enable Apache2"
      ansible.builtin.systemd_service:
        name: apache2
        state: restarted
        enabled: true

ansible-playbook scholar-website.yaml -i hosts

Leave a comment

Turn on JavaScript to leave a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company
Exit mobile version
%%footer%%