avoid duplicated 'name' for CIDRs and manual peers

This commit is contained in:
max.mehl
2022-03-03 11:12:06 +01:00
parent b65e1c6212
commit 3b90b57bfc
3 changed files with 14 additions and 26 deletions

View File

@ -11,7 +11,6 @@ cidrs:
## 10.200.16.1 to 10.200.31.254 ## 10.200.16.1 to 10.200.31.254
## 4,096 usable IP addresses ## 4,096 usable IP addresses
humans: humans:
name: humans
parent: fsfe parent: fsfe
cidr: 10.200.16.0/20 cidr: 10.200.16.0/20
@ -19,7 +18,6 @@ cidrs:
### 10.200.16.1 to 10.200.19.254 ### 10.200.16.1 to 10.200.19.254
### 1,024 usable IP addresses ### 1,024 usable IP addresses
admins: admins:
name: admins
parent: humans parent: humans
cidr: 10.200.16.0/22 cidr: 10.200.16.0/22
@ -27,7 +25,6 @@ cidrs:
### 10.200.20.1 to 10.200.23.254 ### 10.200.20.1 to 10.200.23.254
### 1,024 usable IP addresses ### 1,024 usable IP addresses
others: others:
name: others
parent: humans parent: humans
cidr: 10.200.20.0/22 cidr: 10.200.20.0/22
@ -35,37 +32,26 @@ cidrs:
## 10.200.64.1 to 10.200.127.254 ## 10.200.64.1 to 10.200.127.254
## with 16,384 usable IP addresses ## with 16,384 usable IP addresses
machines: machines:
name: machines
parent: fsfe parent: fsfe
cidr: 10.200.64.0/18 cidr: 10.200.64.0/18
# key of the CIDR you want to use for the client role, # name of the CIDR you want to use for the client role,
# so automatically configured peers (typically VMs) # so automatically configured peers (typically VMs)
machine_cidr: machines machine_cidr: machines
# Peers that are configured manually, typically humans. The created invitation # Peers that are configured manually, typically humans. The created invitation
# file will be stored on the controller machines and has to be imported on the # file will be stored on the controller machines and has to be imported on the
# person's computer manually. 'name' must consist of alphanumeric characters and # person's computer manually.
# dashes, no dots or similar! # * the key (e.g. "linus") is limited to alphanumeric chars and dashes, no dots
# * "cidr" is the name of the CIDR the user shall belong to
# * "admin" defines whether peer should be an admin (true/false). Default: false
manual_peers: manual_peers:
linus: linus:
name: linus
cidr: admins cidr: admins
admin: true admin: true
max.mehl: max-mehl:
name: max-mehl
cidr: admins cidr: admins
admin: true admin: true
albert: albert:
name: albert
cidr: admins cidr: admins
admin: true admin: true
# humans > admins, e.g.
# - { "cidr": "admins", "name": "linus", "admin": "true" }
# humans > others, e.g.
# - { "cidr": "others", "name": "mk", "admin": "false" }
# - { "cidr": "others", "name": "fi", "admin": "false" }
# - { "cidr": "others", "name": "fani", "admin": "false" }
# machines, e.g.
# - { "cidr": "machines", "name": "cont1-plutex", "admin": "false" }

View File

@ -56,6 +56,7 @@
when: "'innernet' not in ansible_facts.packages or 'update' in ansible_run_tags" when: "'innernet' not in ansible_facts.packages or 'update' in ansible_run_tags"
- name: Get existing peers from innernet-server database - name: Get existing peers from innernet-server database
tags: [peers]
shell: 'sqlite3 /var/lib/innernet-server/{{ network_name }}.db "select name from peers;"' shell: 'sqlite3 /var/lib/innernet-server/{{ network_name }}.db "select name from peers;"'
register: existing_peers register: existing_peers
delegate_to: "{{ innernet_server }}" delegate_to: "{{ innernet_server }}"
@ -73,7 +74,7 @@
vars: vars:
peer_name: "{{ innernet_client }}" peer_name: "{{ innernet_client }}"
# Value of the CIDR we defined as the CIDR for machines # Value of the CIDR we defined as the CIDR for machines
peer_cidr: "{{ cidrs[machine_cidr]['name'] }}" peer_cidr: "{{ machine_cidr }}"
# machines are never admins # machines are never admins
peer_admin: "false" peer_admin: "false"
when: when:

View File

@ -68,16 +68,17 @@
tags: [cidr] tags: [cidr]
shell: | shell: |
innernet-server add-cidr "{{ network_name }}" \ innernet-server add-cidr "{{ network_name }}" \
--name "{{ item.value.name }}" \ --name "{{ item.key }}" \
--parent "{{ item.value.parent }}" \ --parent "{{ item.value.parent }}" \
--cidr "{{ item.value.cidr }}" \ --cidr "{{ item.value.cidr }}" \
--yes --yes
loop: "{{ cidrs | dict2items }}" loop: "{{ cidrs | dict2items }}"
when: when:
- item.value.name not in existing_cidrs.stdout_lines - item.key not in existing_cidrs.stdout_lines
# Configure manually defined peers (mostly humans) # Configure manually defined peers (mostly humans)
- name: Get existing peers from innernet-server database - name: Get existing peers from innernet-server database
tags: [peers]
shell: 'sqlite3 /var/lib/innernet-server/{{ network_name }}.db "select name from peers;"' shell: 'sqlite3 /var/lib/innernet-server/{{ network_name }}.db "select name from peers;"'
register: existing_peers register: existing_peers
run_once: true run_once: true
@ -89,12 +90,12 @@
apply: apply:
tags: [peers] tags: [peers]
vars: vars:
peer_name: "{{ item.value.name }}" peer_name: "{{ item.key }}"
peer_cidr: "{{ item.value.cidr }}" peer_cidr: "{{ item.value.cidr }}"
peer_admin: "{{ item.value.admin }}" peer_admin: "{{ item.value.admin | default('false') }}"
loop: "{{ manual_peers | dict2items }}" loop: "{{ manual_peers | dict2items }}"
when: when:
- item.value.name not in existing_peers.stdout_lines - item.key not in existing_peers.stdout_lines
- name: Enable firewall and allow SSH - name: Enable firewall and allow SSH
tags: [listen_port, firewall] tags: [listen_port, firewall]