๐Ÿ“— Ansible playbooks and roles for building an idempotent, interconnected and scalable infrastructure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible-playbooks/roles/mariadb/tasks/add_user.yml

32 lines
999 B

2 years ago
- name: validate input
fail:
msg: user parameters are incorrect
when: (user is not mapping) or (user.name is not defined) or
(user.password is not defined)
- name: get target server hostname
set_fact:
target_server: "{{ mariadb_server | d(services.mariadb.hostname) }}"
- block:
- name: construct keyvalue pairs for privileges
set_fact:
mysql_user_attrs:
- key: "{{ user.name ~ '.*' }}"
value: "ALL"
when: user.privs is not defined
- name: add user to mariadb
community.mysql.mysql_user:
name: "{{ user.name }}"
password: "{{ user.password }}"
priv: "{{ (user.privs | d(mysql_user_attrs | d([]))) | items2dict }}"
config_file: "{{ hostvars[target_server]['mariadb_conf_dir'] | d(mariadb_conf_dir) }}/mariadb.conf"
login_unix_socket: "{{ hostvars[target_server]['mariadb_socket'] | d(mariadb_socket) }}"
check_implicit_admin: yes
delegate_to: "{{ target_server }}"