diff --git a/CICD/plays/nfssqlnodes.yml b/CICD/plays/nfssqlnodes.yml index f2efc9248c3315cc80aef80c3a50a5d0aaa86f21..24a7338397f32ac7e0ca448935f394c77b112d86 100644 --- a/CICD/plays/nfssqlnodes.yml +++ b/CICD/plays/nfssqlnodes.yml @@ -45,8 +45,8 @@ gather_facts: True roles: - { role: upgrade, tags: [ upgrade ] } - - { role: mysql, mysql_type: mysql_server, mysql_root_password: "{{ sqlrootPasswd }}", mysql_user_name: slurmdb, mysql_user_db_name: slurm_acct_db, mysql_user_hosts_group: "{{ groups['ManagementNodes'] }}", mysql_user_password: "{{ slurmdb_passwd }}", tags: [ database ] } - { role: make_filesystems, volumes: "{{ dbvolumes }}" } + - { role: mysql, mysql_type: mysql_server, mysql_root_password: "{{ sqlrootPasswd }}", mysql_user_name: slurmdb, mysql_user_db_name: slurm_acct_db, mysql_user_hosts_group: "{{ groups['ManagementNodes'] }}", mysql_user_password: "{{ slurmdb_passwd }}", tags: [ database ] } - { role: slurm-mysql-config, tags: [database,slurmdb] } tags: [ sql ] diff --git a/roles/mysql/tasks/Centos_7_mysql_server.yml b/roles/mysql/tasks/Centos_7_mysql_server.yml new file mode 100644 index 0000000000000000000000000000000000000000..33f65d3d5eecdc877103b3ba9fa656588b1e7b37 --- /dev/null +++ b/roles/mysql/tasks/Centos_7_mysql_server.yml @@ -0,0 +1,57 @@ +--- +- name: Make sure OS is updated since apt install might fail + apt: + update_cache: yes + become: true + when: ansible_os_family == "Debian" + +- name: "Installing MySQL Debian" + apt: name="{{ server_packages }}" update_cache=yes state=present + become: true + when: ansible_os_family == "Debian" + +- name: Installing MySQL RedHat + yum: name={{ item }} + with_items: "{{ server_packages }}" + become: true + when: ansible_os_family == "RedHat" + +- name: make sure mysql conf directory exists + file: dest=/etc/mysql/conf.d state=directory + become: true + register: mysqldb_confdir_create + +- name: "Starting MySQL" + service: name={{ sqlServiceName }} state=started enabled=true + become: true + +#- name: "Adding root" +# become: true +# mysql_user: name=root host="{{ item }}" password="{{ mysql_root_password }}" login_user=root login_password="{{ mysql_root_password }}" check_implicit_admin=yes +# with_items: +# - "{{ ansible_hostname }}" +# - 127.0.0.1 +# - ::1 +# - localhost + +- name: Check that the slurm_acct_db_directory exists + stat: + path: /var/lib/mysql/slurm_acct_db/ #defined in /vars/filesystems.yaml + register: slurm_acct_db_directory_result + +# this will only work if a completely fresh db gets installed because it gets shipped with a blank root pw +- name: update mysql root password for all root accounts + mysql_user: name=root host=localhost password={{ mysql_root_password }} login_user=root + when: not slurm_acct_db_directory_result.stat.exists and mysqldb_confdir_create.changed + +- name: "Adding user database" + mysql_db: name={{ mysql_user_db_name }} state=present login_user=root login_password={{ mysql_root_password }} + +- name: "Giving priviliges to user" + mysql_user: name={{ mysql_user_name }} host={{ mysql_user_host }} password={{ mysql_user_password }} login_user=root login_password={{ mysql_root_password }} priv={{ mysql_user_db_name }}.*:ALL,GRANT state=present + when: mysql_user_host is defined + +- name: "Giving priviliges to user" + mysql_user: name={{ mysql_user_name }} host={{ hostvars[item].ansible_fqdn }} password={{ mysql_user_password }} login_user=root login_password={{ mysql_root_password }} priv={{ mysql_user_db_name }}.*:ALL,GRANT state=present + with_items: "{{ mysql_user_hosts_group }}" + when: mysql_user_hosts_group is defined diff --git a/roles/mysql/tasks/Ubuntu_18_mysql_server.yml b/roles/mysql/tasks/Ubuntu_18_mysql_server.yml new file mode 100644 index 0000000000000000000000000000000000000000..90dfd18db105f2c939d57a0d198e96f8b52d9346 --- /dev/null +++ b/roles/mysql/tasks/Ubuntu_18_mysql_server.yml @@ -0,0 +1,39 @@ +--- +- name: Make sure OS is updated since apt install might fail + apt: + update_cache: yes + become: true + +- name: "Installing MySQL Debian" + apt: name="{{ server_packages }}" update_cache=yes state=present + become: true + +- name: make sure mysql conf directory exists + file: dest=/etc/mysql/conf.d state=directory + become: true + register: mysqldb_confdir_create + +- name: "Starting MySQL" + service: name={{ sqlServiceName }} state=started enabled=true + become: true + +- name: Check that the slurm_acct_db_directory exists + stat: + path: /var/lib/mysql/slurm_acct_db/ #defined in /vars/filesystems.yaml + register: slurm_acct_db_directory_result + +# this will only work if a completely fresh db gets installed because it gets shipped with a blank root pw +- name: update mysql root password for all root accounts + mysql_user: name=root host=localhost password={{ mysql_root_password }} login_user=root + +- name: "Adding user database" + mysql_db: name={{ mysql_user_db_name }} state=present login_user=root login_password={{ mysql_root_password }} + +- name: "Giving priviliges to user" + mysql_user: name={{ mysql_user_name }} host={{ mysql_user_host }} password={{ mysql_user_password }} login_user=root login_password={{ mysql_root_password }} priv={{ mysql_user_db_name }}.*:ALL,GRANT state=present + when: mysql_user_host is defined + +- name: "Giving priviliges to user" + mysql_user: name={{ mysql_user_name }} host={{ hostvars[item].ansible_fqdn }} password={{ mysql_user_password }} login_user=root login_password={{ mysql_root_password }} priv={{ mysql_user_db_name }}.*:ALL,GRANT state=present + with_items: "{{ mysql_user_hosts_group }}" + when: mysql_user_hosts_group is defined diff --git a/roles/mysql/tasks/main.yml b/roles/mysql/tasks/main.yml index fd7181ba5206b53ab92a9a0802a239a2f0b0fde2..ab7adde90c29badd14283d1008616b249f757a83 100644 --- a/roles/mysql/tasks/main.yml +++ b/roles/mysql/tasks/main.yml @@ -1,3 +1,3 @@ --- - include_vars: "{{ ansible_distribution }}_{{ ansible_distribution_major_version }}.yml" -- include: "{{ mysql_type }}.yml" +- include: "{{ ansible_distribution }}_{{ ansible_distribution_major_version }}_{{ mysql_type }}.yml"