One of the best used application devlopment stack insallation via ansible. It will take few minutes to understand it and you be able to write your own playbooks as well.
Ansible playbook to install LAMP (Linux, Apache, MySQL, PHP) on a target server:
---
- name: Install LAMP Stack
hosts: your-server
become: yes
vars:
mysql_root_password: your_mysql_root_password
tasks:
- name: Install Apache2
apt:
name: apache2
state: present
- name: Install PHP and necessary extensions
apt:
name:
- php
- php-mysql
- libapache2-mod-php
state: present
- name: Install MySQL Server
apt:
name:
- mysql-server
- python3-pymysql
state: present
vars:
mysql_root_password: "{{ mysql_root_password }}"
- name: Configure MySQL root password
mysql_user:
name: root
password: "{{ mysql_root_password }}"
login_unix_socket: /var/run/mysqld/mysqld.sock
- name: Update MySQL configuration
mysql_config:
login_unix_socket: /var/run/mysqld/mysqld.sock
login_user: root
sections:
mysqld:
bind-address: 0.0.0.0
- name: Restart MySQL Service
service:
name: mysql
state: restarted
- name: Configure Apache2
copy:
src: ./apache2.conf
dest: /etc/apache2/apache2.conf
owner: root
group: root
mode: '0644'
- name: Restart Apache2 Service
service:
name: apache2
state: restarted
In this example playbook, we first define the target server(s) using the hosts
keyword. We then specify that we want to become the root user on the server(s) using the become
keyword.
Next, we use the apt
module to install Apache, PHP, and MySQL packages on the target server(s). We also configure the MySQL root password, update the MySQL configuration to allow remote connections, and restart the MySQL and Apache services to apply the changes.
Finally, we copy a custom Apache2 configuration file from the local machine to the remote server, and restart the Apache2 service to apply the changes.
Note that this is just an example playbook, and you may need to modify it to suit your specific requirements. Additionally, you will need to create an inventory file that specifies the IP address or hostname of your target server, and ensure that Ansible is installed on your local machine.
comment if you get it… — )