DevOps Classroomnotes 05/Aug/2022

Ansible Exercise

  • Write an Ansible Playbook for deploying an apache server in the ubuntu instance and installing php
  • Refer Here for the documentation (skip mysql)
  • Manual Steps
sudo apt update
sudo apt install apache2 -y
sudo apt install php libapache2-mod-php php-mysql -y
# create a file in the path /var/www/html/info.php with content
# <?php phpinfo( ); ?>
sudo systemctl enable apache2
sudo systemctl start apache2
  • Refer Here for the playbook developed in the class. Execute this playbook by copying playbook and info.php file on ansible control node. Add your hosts file
ansible-playbook -i hosts phpapache.yaml
  • The other team also wants the same stuff but they want apache and php to run on centos7
  • Manual steps for centos 7 : Refer Here
sudo yum install httpd -y
sudo yum install php php-mysql
# create a file in the path /var/www/html/info.php with content
# <?php phpinfo( ); ?>
sudo systemctl enable httpd
sudo systemctl start httpd
  • Playbook
---
- name: installing apache and php
  become: yes
  hosts: all
  tasks:
    - name: install apache and update ubuntu packages
      ansible.builtin.yum:
        name: httpd
        state: present
    - name: install php packages
      ansible.builtin.yum:
        name:
          - php
          - php-mysql
        state: present
    - name: copy the info.php
      ansible.builtin.copy:
        src: info.php
        dest: /var/www/html/info.php
    - name: ensure the apache service is running and enabled
      ansible.builtin.systemd:
        name: httpd
        enabled: yes
        state: started
  • Exercise:
    • Try installing tomcat 9 on ubuntu 20 using the steps Refer Here
    • Try install tomcat on centos 7 Refer Here

Leave a Reply

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

About continuous learner

devops & cloud enthusiastic learner