Linux - Ansible - use playbook to install mysql - ubuntu(still have problems)
[21:13:54 root@centos7 ansible]#tree . ├── files │ ├── my.cnf │ └── mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz ├── hosts └── install_mysql8.0-v2.yaml [21:26:17 root@centos7 ansible]#cat install_mysql8.0-v2.yaml --- # install mysql-8.0.23-linux-glibc2.12-x86_64.tar.xz # - hosts: webserver2 remote_user: root gather_facts: no vars: mysql_version: 8.0.23 mysql_file: mysql-{{mysql_version}}-linux-glibc2.12-x86_64.tar.xz mysql_root_password: 123456 tasks: - name: install packages apt: name: - libaio1 - numactl state: latest - name: create mysql group group: name=mysql gid=306 - name: create mysql user user: name=mysql uid=306 group=mysql shell=/sbin/nologin system=yes create_home=no home=/data/mysql - name: copy tar to remote host and file mode unarchive: src=/data/ansible/files/{{mysql_file}} dest=/usr/local/ owner=root group=root - name: create linkfile /usr/local/mysql file: src=/usr/local/mysql-{{mysql_version}}-linux-glibc2.12-x86_64 dest=/usr/local/mysql state=link - name: data dir shell: /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/data/mysql tags: data - name: config my.cnf copy: src=/data/ansible/files/my.cnf dest=/etc/my.cnf notify: - restart mysqld - notify message tags: - config - name: service script shell: /bin/cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld - name: PATH variable copy: content='PATH=/usr/local/mysql/bin:$PATH' dest=/etc/profile.d/mysql.sh - name: enable service shell: chkconfig --add mysqld;/etc/init.d/mysqld start -> abend at this , need to check how to enable the service and start for ubuntu? tags: service - name: change password shell: /usr/local/mysql/bin/mysqladmin -uroot password {{mysql_root_password}} handlers: - name: restart mysqld service: name=mysqld state=restarted - name: notify message debug: msg="mysql is restarted"
[20:58:05 root@centos7 ansible]#ansible-playbook install_mysql8.0-v2.yaml
PLAY [webserver2] ***************************************************************************************************************************************
TASK [install packages] *********************************************************************************************************************************
ok: [10.0.0.113]
TASK [create mysql group] *******************************************************************************************************************************
changed: [10.0.0.113]
TASK [create mysql user] ********************************************************************************************************************************
changed: [10.0.0.113]
TASK [copy tar to remote host and file mode] ************************************************************************************************************
changed: [10.0.0.113]
TASK [create linkfile /usr/local/mysql] *****************************************************************************************************************
changed: [10.0.0.113]
TASK [data dir] *****************************************************************************************************************************************
changed: [10.0.0.113]
TASK [config my.cnf] ************************************************************************************************************************************
changed: [10.0.0.113]
TASK [service script] ***********************************************************************************************************************************
changed: [10.0.0.113]
TASK [PATH variable] ************************************************************************************************************************************
changed: [10.0.0.113]
TASK [enable service] ***********************************************************************************************************************************
fatal: [10.0.0.113]: FAILED! => {"changed": true, "cmd": "chkconfig --add mysqld;/etc/init.d/mysqld start", "delta": "0:00:02.125885", "end": "2021-06-14 21:01:08.127660", "msg": "non-zero return code", "rc": 1, "start": "2021-06-14 21:01:06.001775", "stderr": "/bin/sh: 1: chkconfig: not found\nJob for mysqld.service failed because the control process exited with error code.\nSee \"systemctl status mysqld.service\" and \"journalctl -xe\" for details.", "stderr_lines": ["/bin/sh: 1: chkconfig: not found", "Job for mysqld.service failed because the control process exited with error code.", "See \"systemctl status mysqld.service\" and \"journalctl -xe\" for details."], "stdout": "Starting mysqld (via systemctl): mysqld.service failed!", "stdout_lines": ["Starting mysqld (via systemctl): mysqld.service failed!"]}
RUNNING HANDLER [restart mysqld] ************************************************************************************************************************
RUNNING HANDLER [notify message] ************************************************************************************************************************
PLAY RECAP **********************************************************************************************************************************************
10.0.0.113 : ok=9 changed=8 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0

浙公网安备 33010602011771号