k3s-io / k3s-ansible

Apache License 2.0
2.01k stars 802 forks source link

POC: Supporting k3s-ansible with external database #339

Closed peterklijn closed 3 months ago

peterklijn commented 3 months ago

Changes

A (working) proof of concept of supporting external databases in this Ansible setup. This change introduces an option variable use_external_database, which if present uses the k3s-single.service.j2 template, regardless of how many server hosts are defined. Using this together with the extra_server_args variable to pass along a --datastore-endpoint will create a K3s setup using an external datastore.

---
k3s_cluster:
  children:
    server:
      hosts:
        192.168.64.2:
        192.168.64.3:
    agent:
      hosts:
        192.168.64.4:

  # Required Vars
  vars:
    # ...
    token: mytoken
    use_external_database: true
    extra_server_args: "--datastore-endpoint=postgres://username:password@hostname:port/database-name"
    # ...

Linked Issues

https://github.com/k3s-io/k3s-ansible/issues/340

dereknola commented 3 months ago

If you rebase off master, you won't see the lint error around ansible 2.14 anymore.

peterklijn commented 3 months ago

Hi @dereknola, Thanks for the review, I've fixed the lint error and added some documentation to the readme. Could you have another look and let me know if there's anything I need to do before merging?

peterklijn commented 3 months ago

Sorry for the delay, was offsite all last week. This should fix all the lint. As use_external_database is already defined with a default bool value, all attempts to override it must also be a bool, eliminating the need to filter | bool in the when clauses.

Thanks for the review! I've processed your comments 👍