Skip to content

Commit

Permalink
added ansible role files
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Jun 3, 2022
1 parent 0a0c4bc commit f64a1af
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 1 deletion.
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
# ansible-role-mysql
Role Name
=========

A brief description of the role goes here.

Requirements
------------

Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.

Role Variables
--------------

A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.

Dependencies
------------

A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.

Example Playbook
----------------

Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:

- hosts: servers
roles:
- { role: username.rolename, x: 42 }

License
-------

BSD

Author Information
------------------

An optional section for the role authors to include contact information, or a website (HTML is not allowed).
11 changes: 11 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$ANSIBLE_VAULT;1.1;AES256
65363061343765363061663564343063383336393230383663373339346137383233373861623965
3234353965616639383537343866633162663836633961310a316238346665633530613734646134
34346337316334636339356363396463633562333066336461613766393336306631306263346136
3232616166396464620a383833613566613832373631333466356364383830353761653135653261
63353630376266663036386664393139333739633136383738323365363866333231383366656532
31306138653434336535343665323834353131303032346633336634373439386238343665316237
30386165323737613966653366653963643532343031383830613737643130623365386230633231
35333639343065623564366665343731646432666366323461663061633634323934366332616539
62346133323562643766313735613961393966346233303734343164316461343762396436636531
6236326138303839306439616538396266646163633832316363
2 changes: 2 additions & 0 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# handlers file for ansible-role-mysql
53 changes: 53 additions & 0 deletions meta/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)

# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker

# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)

min_ansible_version: 2.9

# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:

#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

55 changes: 55 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
# tasks file for ansible-role-mysql
- name: Install MySQL-server and pip3
yum:
name: mariadb-server, python3-pip
state: latest
update_cache: true
- name: Install PyMySQL
vars:
ansible_python_interpreter: '/usr/bin/python3'
pip:
name: PyMySQL
executable: pip3
- name: ensure mysql is running (and enabled)
service:
name: mariadb
state: started
enabled: yes
- name: test mysql_secure_installation
vars:
ansible_python_interpreter: '/usr/bin/python3'
mysql_secure_installation:
login_password: ''
new_password: '{{ mysql_root_password }}'
user: root
login_host: localhost
hosts: ['localhost', '127.0.0.1', '::1', '10.0.100.160', '10.0.100.44']
change_root_password: true
remove_anonymous_user: true
disallow_root_login_remotely: false
remove_test_db: true
- name: Create root password file
blockinfile:
path: ~/.my.cnf
create: yes
block: |
[client]
user=root
password={{ mysql_root_password }}
- name: Create database user for phpMyAdmin with all database privileges
vars:
ansible_python_interpreter: '/usr/bin/python3'
community.mysql.mysql_user:
name: '{{ mysql_phpmyadmin_username }}'
password: '{{ mysql_phpmyadmin_password }}'
host: "10.0.100.160"
priv: '*.*:ALL,GRANT'
state: present
- name: Add iptables rule to accept connections on 3306 port
ansible.builtin.iptables:
chain: INPUT
source: 0/0
protocol: tcp
destination_port: '3306'
jump: ACCEPT
2 changes: 2 additions & 0 deletions tests/inventory
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
localhost

5 changes: 5 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- ansible-role-mysql
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
# vars file for ansible-role-mysql

0 comments on commit f64a1af

Please sign in to comment.