dj-wasabi/ansible-zabbix-server

Database creation using create.sql.gz

average-joe opened this issue · 4 comments

Describe the bug

While trying to install a fresh Zabbix server instance on a CentOS instance, the playbook will fail during the database creation.

Specifically, failing on this task:

- name: "MySQL | Create database and import file >= 3.0"
  mysql_db:
    login_host: "{{ zabbix_server_mysql_login_host | default(omit) }}"
    login_user: "{{ zabbix_server_mysql_login_user | default(omit) }}"
    login_password: "{{ zabbix_server_mysql_login_password | default(omit) }}"
    login_port: "{{ zabbix_server_mysql_login_port | default(omit) }}"
    login_unix_socket: "{{ zabbix_server_mysql_login_unix_socket | default(omit) }}"
    name: "{{ zabbix_server_dbname }}"
    encoding: "{{ zabbix_server_dbencoding }}"
    collation: "{{ zabbix_server_dbcollation }}"
    state: import
    target: "{{ ls_output_create.stdout }}"
  when:
    - zabbix_version is version_compare('3.0', '>=')
    - zabbix_database_sqlload
    - not done_file.stat.exists
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database

It appears the mysql_db ansible module is unable to unzip the .gz file prior to use. After manually unzipping the create.sql.gz file and then running the playbook again, it will succeed.

Installation method/version

  • Github / latest

Ansible Version
Recently upgraded to Ansible 2.7.

<!--- Paste output from "ansible --version" -->
TASK [dj-wasabi.zabbix-server : MySQL | Create database and import file >= 3.0] **************************************************

<192.168.XX.24> (1, '\r\n\r\n{"msg": "\\ngzip: stdout: Broken pipe\\n", "failed": true, "invocation": {"module_args": {"ssl_key": null, "login_port": 3306, "config_file": "/root/.my.cnf", "target": "/usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz", "encoding": "utf8", "login_user": "root", "login_host": "localhost", "ignore_tables": [], "ssl_ca": null, "login_unix_socket": null, "state": "import", "ssl_cert": null, "login_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", "collation": "utf8_bin", "quick": true, "single_transaction": false, "connect_timeout": 30, "name": "zabbixdb"}}}\r\n', 'Shared connection to 192.168.XX.24 closed.\r\n')
<192.168.XX.24> ESTABLISH SSH CONNECTION FOR USER: ansible
<192.168.XX.24> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/89a7234a26 192.168.XX.24 '/bin/sh -c '"'"'rm -f -r /home/ansible/.ansible/tmp/ansible-tmp-1539869748.41-273338602067385/ > /dev/null 2>&1 && sleep 0'"'"''
<192.168.XX.24> (0, '', '')
fatal: [lab-cms-zabbix.temp -> 192.168.XX.24]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "collation": "utf8_bin",
            "config_file": "/root/.my.cnf",
            "connect_timeout": 30,
            "encoding": "utf8",
            "ignore_tables": [],
            "login_host": "localhost",
            "login_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "login_port": 3306,
            "login_unix_socket": null,
            "login_user": "root",
            "name": "zabbixdb",
            "quick": true,
            "single_transaction": false,
            "ssl_ca": null,
            "ssl_cert": null,
            "ssl_key": null,
            "state": "import",
            "target": "/usr/share/doc/zabbix-server-mysql-4.0.0/create.sql.gz"
        }
    },
    "msg": "\ngzip: stdout: Broken pipe\n"

Targetted hosts
Concerns the following OS(es):

  • CentOS

Expected behavior

The task should succeed and correctly build the zabbix database.

Additional context

I don't recall running into this problem when using Ansible v2.5. Is anyone able to replicate this problem with v2.7?

Hi @average-joe

This morning I updated Ansible on my Mac to 2.7.0 and executed a molecule test (Starting 6 containers, Centos, Ubuntu & Debian for both MySQL/PostgreSQL), no issues at all.

First, @dj-wasabi , thank you for such an exceptional collection of roles!!

I don't know if this is related, but I get a failure to install postgres:

TASK [dj-wasabi.zabbix-server : PostgreSQL | Delegated | Create database] ***********************************************************
fatal: [localhost]: FAILED! => {"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: invalid user: ‘postgres’\n}). For information on working around this, see https://docs.ansible.com/ansible/become.html#becoming-an-unprivileged-user"}

Should the role include a create postgres user task?

Hi @blaisep

It seems that it is an Ansible related issue, see the link in the error. It basically mentions that you can set the property allow_world_readable_tmpfiles=True in the ansible.cfg file.

I will close this issue. If some one still has this issue, please reopen.

'allow_world_readable_tmpfiles = True' in ansible.cfg seems to be the solution.
Now it runs fine...