Syed Khalandar:
Hello team
I hope this message finds you all well. I am reaching out to seek your assistance with a project related to the course “Ansible for Absolute Beginners.”
The project entails developing an Ansible playbook to automate the deployment of the KodeKloud E-Commerce Application. While I have made progress with the playbook, I encountered an issue related to executing MySQL queries. As a result, I am currently facing the following error:
FYI: i am running ansible from my local censtos machine for amazon linux ec2 machine in aws t2.micro
fatal: [server1]: FAILED! => {"changed": false, "msg": "A MySQL module is required: for Python 2.7 either PyMySQL, or MySQL-python, or for Python 3.X mysqlclient or PyMySQL. Consider setting ansible_python_interpreter to use the intended Python version."}
the below is the playbook code
---
- name: Install Apache HTTP Server
hosts: server1
become: true
tasks:
- name: Install firewalld Server
package:
name: firewalld
state: present
- name: Start and enable firewalld Server
service:
name: firewalld
state: started
enabled: yes
- name: Install mariadb Server
package:
name: mariadb-server
state: present
- name: Start and enable mariadb Server
service:
name: mariadb
state: started
enabled: yes
- name: Allow port 3306/tcp in firewall
shell: "firewall-cmd --permanent --zone=public --add-port=3306/tcp"
- name: Reload firewall rules
shell: "firewall-cmd --reload"
# - name: Create the database
# mysql_db:
# name: ecomdb
# state: present
# login_user: root
# login_password: ''
# - name: Create the user
# mysql_user:
# name: ecomuser
# password: ecompassword
# priv: "*.*:ALL"
# state: present
# host: localhost
# login_user: root
# login_password: ''
# - name: Flush privileges
# mysql_db:
# name: '*.*'
# state: flush_privileges
# login_user: root
# login_password: ""
# mysql -u root -p
# CREATE DATABASE ecomdb;
# CREATE USER 'ecomuser'@'localhost' IDENTIFIED BY 'ecompassword';
# GRANT ALL PRIVILEGES ON *.* TO 'ecomuser'@'localhost';
# FLUSH PRIVILEGES;
- name: Install Apache HTTP Server
package:
name: httpd
state: present
- name: Start and enable Apache HTTP Server
service:
name: httpd
state: started
enabled: yes
- name: Install php package
yum:
name: php
state: present
- name: Install php-mysql package
yum:
name: php-mysql
state: present
- name: Allow port 80/tcp in firewall
shell: "firewall-cmd --permanent --zone=public --add-port=80/tcp"
- name: Reload firewall rules
shell: "firewall-cmd --reload"
- name: Replace string in httpd.conf
shell: "sed -i 's/index.html/index.php/g' /etc/httpd/conf/httpd.conf"
- name: Restart httpd service
service:
name: httpd
state: restarted
- name: Install Git package
yum:
name: git
state: present
- name: Clone the repository
git:
repo: <https://github.com/kodekloudhub/learning-app-ecommerce.git>
dest: /var/www/html/
- name: Replace IP address in index.php
shell: "sudo sed -i 's/172.20.1.101/localhost/g' /var/www/html/index.php"
As a temporary solution, I have commented out the problematic lines and am running the MySQL queries manually. However, I would greatly appreciate your guidance to identify the root cause of the issue and find a permanent solution.
To address the problem, I have already attempted installing PyMySQL on my Amazon Linux 2 EC2 server, but unfortunately, this did not resolve the error.
If anyone has encountered a similar issue before or has expertise in Ansible and MySQL integration, I would be grateful for any insights or suggestions you may have.
Thank you all in advance for your support and valuable input. Your assistance will undoubtedly aid in resolving this challenge and further enhance our understanding of Ansible.