dj-wasabi/ansible-zabbix-web

Why is my playbook installing postgresql when I configured the role to configure mysql

maco1717 opened this issue · 3 comments

Hi,

Thanks for the awesome library of roles you have done.

I am quite new to Ansible and looking forward to learn while I improve my systems.

Describe the bug
When trying to use this role to deploy a deploy a zabbix server+zabbix web frontend I get an error running the TASK: postgresql | create database...

The weird thing is I configured the role to use mysql not postgresql at all.

Does postgresql need to be installed and configured for me to use this role?

Installation method/version

  • Ansible Galaxy / 2.6.2

Ansible Version

ansible 2.6.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/marco/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]

Targetted hosts
Concerns the following OS(es):

  • Ubuntu
marco@zabbix-djwasabi:~$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.1 LTS"

Expected behavior
I expect zabbix to get provisioned on the target machine using mysql, not postgresql, I was hoping the postgrep bit to be skipped.

Additional context
here is my playbook


  • hosts: all
    become: yes
    roles:
    • { role: geerlingguy.apache }
    • { role: dj-wasabi.zabbix-server, zabbix_server_database_type: mysql, zabbix_server_database_type_long: mysql, zabbix_server_dbport: 3306 }
    • { role: dj-wasabi.zabbix-web, zabbix_url: monitoring.marco.com, zabbix_server_database_type: mysql, zabbix_server_database_type_long: mysql, zabbix_server_dbport: 3306, zabbix_server_dbuser: root, zabbix_server_dbpassword: super-secure-password }

here is the -vvv output of the task failing

TASK [dj-wasabi.zabbix-server : PostgreSQL | Delegated | Create database] **********
task path: /home/marco/.ansible/roles/dj-wasabi.zabbix-server/tasks/postgresql.yml:10
<192.168.0.67> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.0.67> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/marco/.ansible/cp/1ed75950e5 192.168.0.67 '/bin/sh -c '"'"'echo ~ && sleep 0'"'"''
<192.168.0.67> (0, '/home/marco\n', '')
<192.168.0.67> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.0.67> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/marco/.ansible/cp/1ed75950e5 192.168.0.67 '/bin/sh -c '"'"'( umask 77 && mkdir -p "echo /var/tmp/ansible-tmp-1547164926.76-214840398311343" && echo ansible-tmp-1547164926.76-214840398311343="echo /var/tmp/ansible-tmp-1547164926.76-214840398311343" ) && sleep 0'"'"''
<192.168.0.67> (0, 'ansible-tmp-1547164926.76-214840398311343=/var/tmp/ansible-tmp-1547164926.76-214840398311343\n', '')
Using module file /usr/lib/python2.7/dist-packages/ansible/modules/database/postgresql/postgresql_db.py
<192.168.0.67> PUT /home/marco/.ansible/tmp/ansible-local-3425CZuHTn/tmpujrhUs TO /var/tmp/ansible-tmp-1547164926.76-214840398311343/postgresql_db.py
<192.168.0.67> SSH: EXEC sftp -b - -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/marco/.ansible/cp/1ed75950e5 '[192.168.0.67]'
<192.168.0.67> (0, 'sftp> put /home/marco/.ansible/tmp/ansible-local-3425CZuHTn/tmpujrhUs /var/tmp/ansible-tmp-1547164926.76-214840398311343/postgresql_db.py\n', '')
<192.168.0.67> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.0.67> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/marco/.ansible/cp/1ed75950e5 192.168.0.67 '/bin/sh -c '"'"'setfacl -m u:postgres:r-x /var/tmp/ansible-tmp-1547164926.76-214840398311343/ /var/tmp/ansible-tmp-1547164926.76-214840398311343/postgresql_db.py && sleep 0'"'"''
<192.168.0.67> (0, '', '')
<192.168.0.67> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.0.67> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/marco/.ansible/cp/1ed75950e5 -tt 192.168.0.67 '/bin/sh -c '"'"'sudo -H -S -p "[sudo via ansible, key=nnxudphfmqmhngmwlwyzvlqktbdvmgnq] password: " -u postgres /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-nnxudphfmqmhngmwlwyzvlqktbdvmgnq; /usr/bin/python /var/tmp/ansible-tmp-1547164926.76-214840398311343/postgresql_db.py'"'"'"'"'"'"'"'"' && sleep 0'"'"''
Escalation succeeded
<192.168.0.67> (1, '\r\n\r\n\r\n{"msg": "unable to connect to database: could not connect to server: No such file or directory\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket \"/var/run/postgresql/.s.PGSQL.3306\"?\n", "failed": true, "exception": "Traceback (most recent call last):\n File \"/tmp/ansible_MDHVwW/ansible_module_postgresql_db.py\", line 421, in main\n db_connection = psycopg2.connect(database=maintenance_db, **kw)\n File \"/usr/lib/python2.7/dist-packages/psycopg2/init.py\", line 130, in connect\n conn = _connect(dsn, connection_factory=connection_factory, **kwasync)\nOperationalError: could not connect to server: No such file or directory\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket \"/var/run/postgresql/.s.PGSQL.3306\"?\n\n", "invocation": {"module_args": {"ssl_rootcert": null, "ssl_mode": "prefer", "target": "", "lc_collate": "", "encoding": "", "login_user": "postgres", "login_host": "", "target_opts": "", "db": "zabbix-server", "lc_ctype": "", "maintenance_db": "postgres", "login_unix_socket": "", "state": "present", "template": "", "login_password": "", "owner": "", "port": 3306, "name": "zabbix-server"}}}\r\n', 'Shared connection to 192.168.0.67 closed.\r\n')
<192.168.0.67> ESTABLISH SSH CONNECTION FOR USER: None
<192.168.0.67> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 -o ControlPath=/home/marco/.ansible/cp/1ed75950e5 192.168.0.67 '/bin/sh -c '"'"'rm -f -r /var/tmp/ansible-tmp-1547164926.76-214840398311343/ > /dev/null 2>&1 && sleep 0'"'"''
<192.168.0.67> (0, '', '')
The full traceback is:
Traceback (most recent call last):
File "/tmp/ansible_MDHVwW/ansible_module_postgresql_db.py", line 421, in main
db_connection = psycopg2.connect(database=maintenance_db, **kw)
File "/usr/lib/python2.7/dist-packages/psycopg2/init.py", line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
OperationalError: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.3306"?

fatal: [192.168.0.67 -> 192.168.0.67]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"db": "zabbix-server",
"encoding": "",
"lc_collate": "",
"lc_ctype": "",
"login_host": "",
"login_password": "",
"login_unix_socket": "",
"login_user": "postgres",
"maintenance_db": "postgres",
"name": "zabbix-server",
"owner": "",
"port": 3306,
"ssl_mode": "prefer",
"ssl_rootcert": null,
"state": "present",
"target": "",
"target_opts": "",
"template": ""
}
},
"msg": "unable to connect to database: could not connect to server: No such file or directory\n\tIs the server running locally and accepting\n\tconnections on Unix domain socket "/var/run/postgresql/.s.PGSQL.3306"?\n"
}
to retry, use: --limit @/home/marco/ansible-playbooks/zabbix/zabbix-djwasabi/site.retry

PLAY RECAP *************************************************************************
192.168.0.67 : ok=26 changed=0 unreachable=0 failed=1

but of course this is expected to fail as not configured, I would expect this task to be skipped.

Turns out that the examples I used:

zabbix_server_database_type:
mysql, zabbix_server_database_type_long:

and the documentation mentions:

zabbix_server_database:
mysql, zabbix_server_database_long:

I changed those variables names and the role worked.

Thanks.

Hi @maco1717

Thank you for your answer. I'll make sure this will be consistent.

I merged a PR to fix this. Will close this issue. Thank you for reporting it! 👍