Skip to content

Adding in sudo execution support #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,30 @@
yum: name={{ item }} state=installed
with_items: mysql_pkgs
when: ansible_os_family == 'RedHat'
sudo: yes

- name: Install the mysql packages in Debian derivatives
apt: name={{ item }} state=installed update_cache=yes
with_items: mysql_pkgs
environment: env
when: ansible_os_family == 'Debian'
sudo: yes

- name: Copy the my.cnf file
template: src=my.cnf.{{ ansible_os_family }}.j2 dest={{ mysql_conf_dir }}/my.cnf
notify:
- restart mysql
sudo: yes

- name: Create the directory /etc/mysql/conf.d
file: path=/etc/mysql/conf.d state=directory
notify:
- restart mysql
sudo: yes

- name: Start the mysql services Redhat
service: name={{ mysql_service }} state=started enabled=yes
sudo: yes

- name: update mysql root password for all root accounts
mysql_user: name=root host={{ item }} password={{ mysql_root_db_pass }}
Expand All @@ -45,51 +50,60 @@

- name: copy .my.cnf file with root password credentials
template: src=.my.cnf.j2 dest=~/.my.cnf mode=0600
sudo: no

- name: ensure anonymous users are not in the database
mysql_user: name='' host={{ item }} state=absent
with_items:
- localhost
- "{{ ansible_hostname }}"
sudo: no

- name: remove the test database
mysql_db: name=test state=absent
sudo: no

- name: Create the database's
mysql_db: name={{ item.name }} state=present
with_items: mysql_db
when: mysql_db|lower() != 'none'
sudo: no

- name: Create the database users
mysql_user: name={{ item.name }} password={{ item.pass|default("foobar") }}
priv={{ item.priv|default("*.*:ALL") }} state=present host={{ item.host | default("localhost") }}
with_items: mysql_users
when: mysql_users|lower() != 'none'
sudo: no

- name: Create the replication users
mysql_user: name={{ item.name }} host="%" password={{ item.pass|default("foobar") }}
priv=*.*:"REPLICATION SLAVE" state=present
with_items: mysql_repl_user
when: mysql_repl_role == 'master'
sudo: no

- name: Check if slave is already configured for replication
mysql_replication: mode=getslave
ignore_errors: true
register: slave
when: mysql_repl_role == 'slave'
sudo: no

- name: Ensure the hostname entry for master is available for the client.
lineinfile: dest=/etc/hosts regexp="{{ mysql_repl_master }}" line="{{ hostvars[mysql_repl_master].ansible_default_ipv4.address + " " + mysql_repl_master }}" state=present
when: slave|failed and mysql_repl_role == 'slave' and mysql_repl_master is defined
sudo: no

- name: Get the current master servers replication status
mysql_replication: mode=getmaster
delegate_to: "{{ mysql_repl_master }}"
register: repl_stat
when: slave|failed and mysql_repl_role == 'slave' and mysql_repl_master is defined
sudo: no

- name: Change the master in slave to start the replication
mysql_replication: mode=changemaster master_host={{ mysql_repl_master }} master_log_file={{ repl_stat.File }} master_log_pos={{ repl_stat.Position }} master_user={{ mysql_repl_user[0].name }} master_password={{ mysql_repl_user[0].pass }}
when: slave|failed and mysql_repl_role == 'slave' and mysql_repl_master is defined

sudo: no