{
"$type": "com.whtwnd.blog.entry",
"content": "# Getting Down to the Basics\n\nThis will be an ongoing task and is in a private repo currently. However, I wanted to share the core of the playbook here. Check back periodically where I will make adjustments to include other best practices. Once I feel like this is in a solid state, I will open up the github repo for easy of use. \n\n## Before You Copy Pasta\n\nNotice the variables-you will need to add your own vars file, inventory file, and your ansible.cfg file. This is not complete, but works in its current state. Feel free to use at your own discretion.\n\n\n\n```yml\n\n- hosts: all\n become: true\n vars_files:\n - external vars file location #add your own var location\n\n\n tasks:\n \n - name: update repository index\n apt:\n update_cache: yes\n \n - name: install mariadb and related plugins\n apt:\n name: mariadb-server\n \n - name: create /data/database directory and mount\n file:\n path: /data/database\n state: directory\n owner: mysql\n\n - name: Adds Python3\n apt: pkg=\"python3\" state=present\n when: ansible_os_family =='Debian'\n\n - name: Adds Python2\n apt: pkg=\"python2\" state=present\n when: ansible_os_family =='Debian'\n\n - name: Install Python3-mysqldb\n apt: pkg=\"python3-mysqldb\" state=present\n when: ansible_os_family =='Debian'\n\n - name: Change root user password on first run\n mysql_user: login_user=root\n login_password=\"{{ mysql_root_password }}\"\n check_implicit_admin=yes\n name=root\n password={{ mysql_root_password }}\n priv=*.*:ALL,GRANT\n host=\"localhost\"\n\n - name: delete anonymous MySQL server user\n mysql_user: login_user=root\n login_password='{{ mysql_root_password }}'\n check_implicit_admin=yes\n user=\"\"\n host=\"localhost\"\n state=\"absent\"\n\n - name: remove the MySQL test database\n action: mysql_db login_user=root login_password=\"{{ mysql_root_password }}\" db=test state=absent\n\n - name: Secures the MySQL root user for IPV6 localhost (::1)\n mysql_user: login_user=root\n login_password='{{ mysql_root_password }}'\n check_implicit_admin=yes\n user=root\n host=\"::1\"\n no_log: yes\n\n - name: Secures the MySQL root user for IPV4 localhost (127.0.0.1)\n mysql_user: login_user=root\n login_password='{{ mysql_root_password }}'\n check_implicit_admin=yes\n user=root\n host=\"127.0.0.1\"\n no_log: yes\n\n - name: Secures the MySQL root user for localhost domain (localhost)\n mysql_user: login_user=root\n login_password='{{ mysql_root_password }}'\n check_implicit_admin=yes\n user=root\n host=\"localhost\"\n no_log: yes\n\n - name: Secures the MySQL root user for server_hostname domain\n mysql_user: login_user=root\n login_password='{{ mysql_root_password }}'\n check_implicit_admin=yes\n user=root\n host=\"{{ server_fqdn }}\"\n no_log: yes\n\n - name: Create /var/log/mariadb directory\n file:\n path: /var/log/mariadb\n state: directory\n owner: mysql\n\n - name: Stop mariadb service\n ansible.builtin.service: \n name: mariadb\n state: stopped\n\n - name: Copy var/lib/mysql to /data/database\n ansible.builtin.copy: \n remote_src: yes\n src: /var/lib/mysql/\n dest: /data/database/\n owner: mysql\n group: mysql\n\n - name: Copy preconfigured config file for mariadb\n ansible.builtin.copy:\n src: location for template conf file\n dest: /etc/mysql/mariadb.conf.d\n owner: root\n group: root\n \n - name: Start mariadb service\n ansible.builtin.service:\n name: mariadb\n state: started\n\n```",
"createdAt": "2022-01-01",
"title": "Basic MariaDB Install Playbook",
"visibility": "public"
}