Simplify configuration by moving all the vars into config.ini
The navigation through a bunch of config files, all with just a few lines in it is cumbersome. This change moves all the configuration into a centralized `config.ini` that way it's easier for me to get a quick overview of the setup. The `config.ini` acts as another inventory and is therefore references as such by the ansible.cfg. The `inventory.ini` (which is generated by terraform in the provisioning-step) is not affected by this change.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
[defaults]
|
||||
nocows = True
|
||||
inventory = inventory.ini
|
||||
inventory = inventory.ini,config.ini
|
||||
display_skipped_hosts = False
|
||||
error_on_undefined_vars = True
|
||||
|
||||
16
k3s/config.ini
Normal file
16
k3s/config.ini
Normal file
@@ -0,0 +1,16 @@
|
||||
[all:vars]
|
||||
k8s_api_endpoint = "{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}"
|
||||
|
||||
[k3s_cluster:vars]
|
||||
ansible_user = root
|
||||
# note the space between the IPs!
|
||||
dns_servers = 8.8.8.8 8.8.4.4
|
||||
|
||||
[agent:vars]
|
||||
ansible_ssh_common_args = -o StrictHostKeyChecking=accept-new -o ProxyCommand="ssh -p 1022 -W %h:%p -q root@{{ k8s_api_endpoint }}"
|
||||
k3s_version = v1.31.6+k3s1
|
||||
|
||||
[server:vars]
|
||||
ansible_ssh_common_args = '-o StrictHostKeyChecking=accept-new'
|
||||
ansible_port = 1022
|
||||
k3s_version = v1.31.6+k3s1
|
||||
@@ -1,3 +0,0 @@
|
||||
ansible_ssh_common_args: -o StrictHostKeyChecking=accept-new -o ProxyCommand="ssh -p 1022 -W %h:%p -q root@{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}"
|
||||
ansible_port: 22
|
||||
k3s_version: v1.31.6+k3s1
|
||||
@@ -1,5 +0,0 @@
|
||||
ansible_user: root
|
||||
api_endpoint: "{{ hostvars[groups['server'][0]]['ansible_host'] | default(groups['server'][0]) }}"
|
||||
|
||||
# note the space between the IPs!
|
||||
dns_servers: 8.8.8.8 8.8.4.4
|
||||
@@ -1,3 +0,0 @@
|
||||
ansible_ssh_common_args: '-o StrictHostKeyChecking=accept-new'
|
||||
ansible_port: 1022
|
||||
k3s_version: v1.31.6+k3s1
|
||||
@@ -2,18 +2,18 @@
|
||||
fetch:
|
||||
src: /etc/rancher/k3s/k3s.yaml
|
||||
dest: "{{ lookup('env', 'HOME') }}/.kube/config.orig"
|
||||
flat: true
|
||||
flat: True
|
||||
register: loaded_kube_config
|
||||
- name: Copy kube-config to correct location
|
||||
delegate_to: localhost
|
||||
copy:
|
||||
src: "{{ lookup('env', 'HOME') }}/.kube/config.orig"
|
||||
dest: "{{ lookup('env', 'HOME') }}/.kube/config"
|
||||
when: hostvars[groups['server'][0]]['loaded_kube_config'] is changed
|
||||
when: loaded_kube_config is changed
|
||||
- name: Use correct ip-address for k8s-cluster
|
||||
delegate_to: localhost
|
||||
lineinfile:
|
||||
path: "{{ lookup('env', 'HOME') }}/.kube/config"
|
||||
regexp: '^(\s*server: https://).*(:\d+)$'
|
||||
line: \g<1>{{ hostvars[groups['server'][0]]['api_endpoint'] }}\g<2>
|
||||
line: \g<1>{{ k8s_api_endpoint }}\g<2>
|
||||
backrefs: yes
|
||||
|
||||
Reference in New Issue
Block a user