Skip to content

Commit

Permalink
change to shell
Browse files Browse the repository at this point in the history
  • Loading branch information
Aethylred committed Nov 11, 2024
1 parent cbef8bf commit f724c05
Showing 1 changed file with 21 additions and 30 deletions.
51 changes: 21 additions & 30 deletions tasks/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,39 @@
# task file for initialising and updating databse if configured

- name: Check Kea DHCP database version
ansible.builtin.command:
argv:
- /usr/sbin/kea-admin
- db-version
- "{% if 'type' in kea_dhcp_database_config %}{{ kea_dhcp_database_config.type }}{% endif %}"
- "{% if 'user' in kea_dhcp_database_config %}-u {{ kea_dhcp_database_config.user }}{% endif %}"
- "{% if 'database' in kea_dhcp_database_config %}-n {{ kea_dhcp_database_config.database }}{% endif %}"
- "{% if 'password' in kea_dhcp_database_config %}-p {{ kea_dhcp_database_config.password }}{% endif %}"
- "{% if 'port' in kea_dhcp_database_config %}-P {{ kea_dhcp_database_config.port }}{% endif %}"
- "{% if 'host' in kea_dhcp_database_config %}-h {{ kea_dhcp_database_config.host }}{% endif %}"
ansible.builtin.shell:
cmd: "/usr/sbin/kea-admin db-version {{ kea_dhcp_database_config.type }}\
{% if 'user' in kea_dhcp_database_config %}-u {{ kea_dhcp_database_config.user }}{% endif %}\
{% if 'database' in kea_dhcp_database_config %}-n {{ kea_dhcp_database_config.database }}{% endif %}\
{% if 'password' in kea_dhcp_database_config %}-p {{ kea_dhcp_database_config.password }}{% endif %}\
{% if 'port' in kea_dhcp_database_config %}-P {{ kea_dhcp_database_config.port }}{% endif %}\
{% if 'host' in kea_dhcp_database_config %}-h {{ kea_dhcp_database_config.host }}{% endif %}"
register: kea_dhcp_db_version
changed_when: false
ignore_errors: true
# no_log: true

- name: Initialise Kea DHCP database # noqa: no-changed-when
ansible.builtin.command:
argv:
- /usr/sbin/kea-admin
- db-init
- "{% if 'type' in kea_dhcp_database_config %}{{ kea_dhcp_database_config.type }}{% endif %}"
- "{% if 'user' in kea_dhcp_database_config %}-u {{ kea_dhcp_database_config.user }}{% endif %}"
- "{% if 'database' in kea_dhcp_database_config %}-n {{ kea_dhcp_database_config.database }}{% endif %}"
- "{% if 'password' in kea_dhcp_database_config %}-p {{ kea_dhcp_database_config.password }}{% endif %}"
- "{% if 'port' in kea_dhcp_database_config %}-P {{ kea_dhcp_database_config.port }}{% endif %}"
- "{% if 'host' in kea_dhcp_database_config %}-h {{ kea_dhcp_database_config.host }}{% endif %}"
ansible.builtin.shell:
cmd: "/usr/sbin/kea-admin db-init {{ kea_dhcp_database_config.type }}\
{% if 'user' in kea_dhcp_database_config %}-u {{ kea_dhcp_database_config.user }}{% endif %}\
{% if 'database' in kea_dhcp_database_config %}-n {{ kea_dhcp_database_config.database }}{% endif %}\
{% if 'password' in kea_dhcp_database_config %}-p {{ kea_dhcp_database_config.password }}{% endif %}\
{% if 'port' in kea_dhcp_database_config %}-P {{ kea_dhcp_database_config.port }}{% endif %}\
{% if 'host' in kea_dhcp_database_config %}-h {{ kea_dhcp_database_config.host }}{% endif %}"
when: kea_dhcp_db_version is failed
notify: restart kea-dhcp
# no_log: true


- name: Update Kea DHCP database # noqa: no-changed-when
ansible.builtin.command:
argv:
- /usr/sbin/kea-admin
- db-upgrade
- "{% if 'type' in kea_dhcp_database_config %}{{ kea_dhcp_database_config.type }}{% endif %}"
- "{% if 'user' in kea_dhcp_database_config %}-u {{ kea_dhcp_database_config.user }}{% endif %}"
- "{% if 'database' in kea_dhcp_database_config %}-n {{ kea_dhcp_database_config.database }}{% endif %}"
- "{% if 'password' in kea_dhcp_database_config %}-p {{ kea_dhcp_database_config.password }}{% endif %}"
- "{% if 'port' in kea_dhcp_database_config %}-P {{ kea_dhcp_database_config.port }}{% endif %}"
- "{% if 'host' in kea_dhcp_database_config %}-h {{ kea_dhcp_database_config.host }}{% endif %}"
ansible.builtin.shell:
cmd: "/usr/sbin/kea-admin db-upgrade {{ kea_dhcp_database_config.type }}\
{% if 'user' in kea_dhcp_database_config %}-u {{ kea_dhcp_database_config.user }}{% endif %}\
{% if 'database' in kea_dhcp_database_config %}-n {{ kea_dhcp_database_config.database }}{% endif %}\
{% if 'password' in kea_dhcp_database_config %}-p {{ kea_dhcp_database_config.password }}{% endif %}\
{% if 'port' in kea_dhcp_database_config %}-P {{ kea_dhcp_database_config.port }}{% endif %}\
{% if 'host' in kea_dhcp_database_config %}-h {{ kea_dhcp_database_config.host }}{% endif %}"
when:
- kea_dhcp_db_version.stdout != kea_dhcp_version
- kea_dhcp_db_version is succeeded
Expand Down

0 comments on commit f724c05

Please sign in to comment.