It's me again...
I'm learning ansible. I want to deploy a Wordpress server, so I've install mysql correctly. But durring the creation of the Database I've received the following error :
[vm1devops]: FAILED! => {"changed": false, "msg": "unable to find
/home/ERTYerty1234/.my.cnf. Exception message: (1045, \"Access denied
for user 'ERTYerty1234'#'localhost' (using password: NO)\")"}
So I've add the following line :
sudo: True
The database create corretcly, but now when I want to acces on my VM. the Wordpress website can't access the Database. Any idea why ?
Here is how is configure MySQL on my files :
mysql/defaults/main.yml
wp_mysql_db: wordpress
wp_mysql_user: ERTYerty1234
wp_mysql_password: arandompassword
mysql/tasks/main.yml
- name: Create mysql database
mysql_db: name={{ wp_mysql_db }} state=present
#EDIT
- name: Create mysql user
mysql_user:
login_user:{{ wp_mysql_user }}
login_password:{{ wp_mysql_password }}
host:localhost
append_privs:true
priv:'*.*:REQUIRESSL'
host:%
name={{ wp_mysql_user }}
password={{ wp_mysql_password }}
And here are the roles installed on the server :
server/tasks/main.yml
- name: Update apt cache
apt: update_cache=yes cache_valid_time=3600
sudo: yes
- name: Install required software
apt: name={{ item }} state=present
sudo: yes
with_items:
- apache2
- mysql-server
- php7.0-mysql
- php7.0
- libapache2-mod-php7.0
- php7.0-mcrypt
- python-mysqldb
If someone have an idea here. It could be great. THanks a lot.
Related
I am trying to load files into MySQL RDS using ansible-playbook
tasks:
- name: loadBase
block:
- name: copy loadBase files to target
copy: src=../../myApp/{{ item }}
dest=/tmp/{{ item | basename }}
owner=tomcat group=tomcat mode=0600
with_items: "{{ data.loadBase }}"
- name: load loadBase files into target mysql
shell: mysql -h {{ db_host }} -u root -p{{ db_root_password }} {{ db_name }} < /tmp/{{ item | basename }}
with_items: "{{ data.loadBase }}"
no_log: true
- name: cleanup loadBase files on target
file: path=/tmp/{{ item | basename }}
state=absent
with_items: "{{ data.loadBase }}"
when: loadBase
I am using the following config file which is used by the ansible playbook
Config file:
# data files, relative to the source code root, to be
# conditionally run during a deployment
data:
loadBase:
- data/src/main/sql/structure.sql
- data/src/main/sql/data.sql
- data/src/main/sql/update.sql
I see that the .sql files are being added to the /tmp folder in the app server from the ansible server. But I see that the data is not loading to MySQL RDS and I see the following error
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-\nansible_ssh_common_args: '-o ProxyCommand=\"ssh -W %h:%p -q root#bastion-myapp' at line 1",
I am using MySQL RDS Engine version 8.0.11.
Its trying to connect to the bastion host again and its failing?
ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q bastion-app.org"'
Any help, what's wrong here?
Why not using the Ansible MySQL module?
See Insert data into mysql tables using ansible and https://docs.ansible.com/ansible/2.5/modules/mysql_db_module.html:
# Copy database dump file to remote host and restore it to database 'my_db'
- name: Copy database dump file
copy:
src: dump.sql.bz2
dest: /tmp
- name: Restore database
community.mysql.mysql_db:
name: my_db
state: import
target: /tmp/dump.sql.bz2
I am trying to get a coverage report in GitHub Actions
but when I run the pipeline I gives me this error:
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock
Then I search around add added the sudo mysql start service and now I get this error, but I don't know were or have to write mit -root -password and the -host?
Access denied for user 'root'#'localhost' (using password: YES)")
how do I do that?
name: Django CI
on:
push:
branches: [ unittests ]
paths-ignore: '**/SkoleProtocol/attendanceCode/tests/test_selenium.py'
pull_request:
branches: [ unittests ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.7, 3.8, 3.9]
steps:
- uses: actions/checkout#v2
- name: Set up Python 3.7
uses: actions/setup-python#v2
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Create test database
run: |
sudo service mysql start
- name: Coverage report
run: |
pip install coverage
coverage run manage.py test
coverage report
- name: Lint with flake8
run: |
pip install flake8
flake8 ./attendanceCode --exit-zero # Exit with status code "0" even if there are errors.
- name: Django Tests
run: |
python3 manage.py test
Two things that stand out.
Do you happen to have the credentials in an env file else where?
- name: Create test database
run: |
sudo service mysql start
You just happen to start the service rather than creating the database.
Try:
sudo /etc/init.d/mysql start // To start the service
mysql -uroot -proot -e "CREATE DATABASE __dbname__;"
I am trying to install MySQL version 8.0.21 using ansible. I have downloaded the required tar file from the MySQL community and tried to install using dpkg command but found issues while passing passwords.
- name: Set MySQL root password before installing
debconf: name='mysql-server' question='mysql-server/root_password' value='{{MySQL_root_pass | quote}}' vtype='password'
become: yes
- name: Confirm MySQL root password before installing
debconf: name='mysql-server' question='mysql-server/root_password_again' value='{{MySQL_root_pass | quote}}' vtype='password'
become: yes
- name: Install my_package
apt: deb="required_package.deb"
become: true
become_method: sudo
This is my YAML.The mysql version is installed with an empty password
What about the role from geerlingguy
ansible-galaxy install geerlingguy.mysql
After installing you yml like this:
- hosts: YOUR_SERVER_IP_HERE
become: yes
vars_files:
- vars/main.yml
roles:
- { role: geerlingguy.mysql }
pre_tasks:
- name: Install the MySQL repo.
yum:
name: http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
state: present
when: ansible_os_family == "RedHat"
- name: Override variables for MySQL (RedHat).
set_fact:
mysql_daemon: mysqld
mysql_packages: ['mysql-server']
mysql_log_error: /var/lib/mysql/error.log
mysql_syslog_tag: mysqld
mysql_pid_file: /var/run/mysqld/mysqld.pid
mysql_socket: /var/lib/mysql/mysql.sock
when: ansible_os_family == "RedHat"
Make sure to updat the vars/main.yml file including the version you wish!
I'm dealing with a project in Symfony. It came with a Vagrant file. When I vagrant up, this comes out:
ERROR! no action detected in task. This often indicates a misspelled
module name, or incorrect module path.
The error appears to be in
'/home/chris/Projects/TechAnalyzePlatform/deploy/ansible/roles/db/tasks/mysql.yml':
line 16, column 5, but may be elsewhere in the file depending on the
exact syntax problem.
The offending line appears to be:
# http://ansible.cc/docs/modules.html#mysql-user
- name: update mysql root password for all root accounts
^ here
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
The mysql.yml file contains the following:
---
# MySQL setup
- name: Install MySQL/MariaDB
action: yum name={{ item }}
with_items:
- MySQL-python
- perl-Cache-Cache
- mariadb
- mariadb-server
- name: Start the MySQL service
action: service name=mariadb state=started enabled=yes
# 'localhost' needs to be the last item for idempotency, see
# http://ansible.cc/docs/modules.html#mysql-user
- name: update mysql root password for all root accounts
mysql_user: name=root host={{ item }} password=admin priv=*.*:ALL,GRANT
with_items:
- "{{ ansible_hostname }}"
- 127.0.0.1
- ::1
- localhost
- name: create /.my.cnf
template: src=my.cnf dest=~/.my.cnf
The module exists, what kind of action should I insert there? What can cause this?
Many thanks
Solution: Update Ansible. Solved.
I need to take a backup of all existing MySQL databases on my server with Ansible.
I'm aware of mysql_db module. It takes the names of the databases I'd like to manipulate on one by one, so I must get the list of existing databases before using that module.
Is there any way to backup all MySQL databases at once or to get a list of existing databases with Ansible?
A patch to adds name=all that allows a user to dump or import all data was merged into devel recently, it's not available yet in 1.9.1, but it's already shown in this part of the documentation.
# Dumps all databases to hostname.sql
- mysql_db: state=dump name=all target=/tmp/{{ inventory_hostname }}.sql
Hopefully this will soon be available in a stable release.
(Run sudo pip install ansible --upgrade to upgrade.)
The mysql_db module uses the mysqldump executable under the hood, which in turn provides an --all-databases switch, it's just that the Ansible module does not provide an option to use it via the module.
I would suggest using mysqldump executable via command module for now and in the meantime file a feature request on Ansible's GitHub to add support for it.
Something like this should get you going for now:
- name: Dump all MySQL databases to a single file
command: mysqldump --opt -uroot --all-databases --result-file=/tmp/all-dbs.sql
Adjust the options to mysqldump as desired: http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html
Update Nov 26, 2016:
A patch adding name=all was added to the mysql_db module on May 12, 2015, so the recommended way to dump all databases is:
# Dumps all databases to hostname.sql
- mysql_db: state=dump name=all target=/tmp/{{ inventory_hostname }}.sql
Alternative way, each database in separate file.
---
# This playbook backups all mysql databases into separate files.
- name: backup mysql
vars:
- exclude_db:
- "Database"
- "information_schema"
- "performance_schema"
- "mysql"
tasks:
- name: get db names
shell: 'mysql -u root -p{{ vault_root_passwd }} -e "show databases;" '
register: dblist
- name: backup databases
mysql_db:
state: dump
name: "{{ item }}"
target: "/tmp/{{ item }}.sql"
login_user: root
login_password: "{{ vault_root_passwd }}"
with_items: "{{ dblist.stdout_lines | difference(exclude_db) }}"