Skip to content

Commit

Permalink
* Don't put objects which are in absent state in proxysql.cnf
Browse files Browse the repository at this point in the history
  • Loading branch information
timorunge committed Nov 13, 2018
1 parent b6f0104 commit b08f72a
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 40 deletions.
90 changes: 50 additions & 40 deletions templates/proxysql.cnf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,17 @@ mysql_servers =
{% if proxysql_backend_servers is defined %}
{% for server in proxysql_backend_servers %}
{
{% for key, value in proxysql_backend_servers[server].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% if ("state" in proxysql_backend_servers[server] and proxysql_backend_servers[server].state != "absent") or ("state" not in proxysql_backend_servers[server]) %}
{% for key, value in proxysql_backend_servers[server].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
}
{% if not loop.last %},{% endif %}
{% endfor %}
Expand All @@ -94,15 +96,17 @@ mysql_users:
{% if proxysql_mysql_users is defined %}
{% for user in proxysql_mysql_users %}
{
{% for key, value in proxysql_mysql_users[user].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% if ("state" in proxysql_mysql_users[user] and proxysql_mysql_users[user].state != "absent") or ("state" not in proxysql_mysql_users[user]) %}
{% for key, value in proxysql_mysql_users[user].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
}
{% if not loop.last %},{% endif %}
{% endfor %}
Expand All @@ -115,15 +119,17 @@ mysql_query_rules:
{% if proxysql_query_rules is defined %}
{% for query_rule in proxysql_query_rules %}
{
{% for key, value in proxysql_query_rules[query_rule].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% if ("state" in proxysql_query_rules[query_rule] and proxysql_query_rules[query_rule].state != "absent") or ("state" not in proxysql_query_rules[query_rule]) %}
{% for key, value in proxysql_query_rules[query_rule].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
}
{% if not loop.last %},{% endif %}
{% endfor %}
Expand All @@ -136,15 +142,17 @@ mysql_replication_hostgroups =
{% if proxysql_replication_hostgroups is defined %}
{% for replication_hostgroup in proxysql_replication_hostgroups %}
{
{% for key, value in proxysql_replication_hostgroups[replication_hostgroup].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% if ("state" in proxysql_replication_hostgroups[replication_hostgroup] and proxysql_replication_hostgroups[replication_hostgroup].state != "absent") or ("state" not in proxysql_replication_hostgroups[replication_hostgroup]) %}
{% for key, value in proxysql_replication_hostgroups[replication_hostgroup].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
}
{% if not loop.last %},{% endif %}
{% endfor %}
Expand All @@ -157,15 +165,17 @@ proxysql_servers =
{% if proxysql_proxysql_servers is defined %}
{% for proxysql_server in proxysql_proxysql_servers %}
{
{% for key, value in proxysql_proxysql_servers[proxysql_server].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% if ("state" in proxysql_proxysql_servers[proxysql_server] and proxysql_proxysql_servers[proxysql_server].state != "absent") or ("state" not in proxysql_proxysql_servers[proxysql_server]) %}
{% for key, value in proxysql_proxysql_servers[proxysql_server].items() %}
{% if key not in proxysql_ignore_template_keys %}
{% if value is number %}
{{ key }} = {{ value }}
{% else %}
{{ key }} = "{{ value }}"
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
{% endfor %}
{% endif %}
}
{% if not loop.last %},{% endif %}
{% endfor %}
Expand Down
41 changes: 41 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,19 @@
max_replication_lag: 5
status: OFFLINE_HARD
weight: 1
mysql-srv4-hg2:
comment: mysql-srv4-hg2
hostgroup: 2
hostname: 172.16.77.104
login_host: "{{ proxysql_login_admin_host }}"
login_password: "{{ proxysql_login_admin_password }}"
login_port: "{{ proxysql_login_admin_port }}"
login_user: "{{ proxysql_login_admin_user }}"
max_connections: 2000
max_replication_lag: 5
status: OFFLINE_HARD
state: absent
weight: 1
proxysql_proxysql_servers:
proxysql-srv-1:
comment: proxysql-srv-1
Expand Down Expand Up @@ -145,6 +158,21 @@
password: dr0wssaP
transaction_persistent: 1
username: user2
user3:
active: 1
backend: 1
default_hostgroup: 1
fast_forward: 0
frontend: 1
login_host: "{{ proxysql_login_admin_host }}"
login_password: "{{ proxysql_login_admin_password }}"
login_port: "{{ proxysql_login_admin_port }}"
login_user: "{{ proxysql_login_admin_user }}"
max_connections: 1000
password: w0rdPass
state: absent
transaction_persistent: 1
username: user3
proxysql_query_rules:
catchall:
active: 1
Expand Down Expand Up @@ -182,5 +210,18 @@
match_pattern: ^SELECT.*
negate_match_pattern: 0
rule_id: 3
delete:
active: 0
apply: 0
destination_hostgroup: 1
flagIN: 0
login_host: "{{ proxysql_login_admin_host }}"
login_password: "{{ proxysql_login_admin_password }}"
login_port: "{{ proxysql_login_admin_port }}"
login_user: "{{ proxysql_login_admin_user }}"
match_pattern: ^DELETE.*
negate_match_pattern: 0
rule_id: 4
state: absent
roles:
- timorunge.proxysql
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proxysql_ignore_template_keys:
- login_host
- login_password
- login_user
- state

# For those variables ProxySQL needs a restart to take effect
# Type: List
Expand Down

0 comments on commit b08f72a

Please sign in to comment.