Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add switch scenario #69

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/molecule-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
ansible: ["2.9", "latest"]
scenario: ["ring", "star", "openwrt"]
scenario: ["ring", "star", "openwrt", "switch"]
steps:
- uses: actions/checkout@v2
- name: Install dependencies
Expand Down
16 changes: 13 additions & 3 deletions molecule/default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@
command: "ping -c 1 {{ item }}"
with_items: "{{ ansible_play_batch }}"
changed_when: false
register: ping_results
register: _ping

- name: Show ping results
- name: Show ping info
debug:
var: ping_results
var: _ping

- name: Show vpn hosts data
command: "cat /etc/tinc/{{ tinc_netname }}/hosts/*"
changed_when: false
register: _hosts

- name: Debug hostfiles
debug:
var: _hosts

1 change: 1 addition & 0 deletions molecule/switch/Dockerfile.j2
1 change: 1 addition & 0 deletions molecule/switch/converge.yml
62 changes: 62 additions & 0 deletions molecule/switch/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
lint: |
set -e
yamllint .
ansible-lint -vv --exclude=.tox
scenario:
name: switch
dependency:
name: galaxy
driver:
name: docker
verifier:
name: ansible
provisioner:
name: ansible
log: True
options:
vvv: True
inventory:
group_vars:
tinc_nodes:
tinc_mode: switch
host_vars:
tinc-switch-1:
tinc_vpn_ip: 10.10.0.15
tinc-switch-2:
tinc_vpn_ip: 10.10.0.15
tinc-switch-3:
tinc_vpn_ip: 10.10.0.15
platforms:
- name: tinc-switch-1
image: ubuntu-20.04
privileged: true
command: /lib/systemd/systemd
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
etc_hosts: &etchosts
tinc-switch-1: 10.10.0.11
tinc-switch-2: 10.10.0.12
tinc-switch-3: 10.10.0.13
groups: &tincgroups
- tinc_nodes
- tinc_spine_nodes
- tinc_leaf_nodes

- name: tinc-switch-2
image: ubuntu-20.04
privileged: true
command: /lib/systemd/systemd
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
etc_hosts: *etchosts
groups: *tincgroups

- name: tinc-switch-3
image: ubuntu-20.04
privileged: true
command: /lib/systemd/systemd
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup:ro
etc_hosts: *etchosts
groups: *tincgroups
1 change: 1 addition & 0 deletions molecule/switch/verify.yml
13 changes: 10 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@
notify:
- Restart Service

- name: Check whether /etc/tinc/netname/hosts/inventory_hostname contains public key
- name: "Check whether /etc/tinc/netname/hosts/{{ inventory_hostname | replace('.','_') | replace('-','_') }} contains public key"
lineinfile:
dest: "/etc/tinc/{{ tinc_netname }}/hosts/{{ inventory_hostname | replace('.','_') | replace('-','_') }}"
line: "-----END RSA PUBLIC KEY-----"
mode: "0600"
create: yes
check_mode: yes
register: contains_publickey_ending

Expand All @@ -81,14 +83,14 @@

- name: Generate tinc keys and append public key to host file
block:
- name: Create using tincd -K
- name: Generate keys with tincd -K
command: "tincd -n {{ tinc_netname }} -K{{ tinc_key_size }}"
args:
creates: "/etc/tinc/{{ tinc_netname }}/rsa_key.priv"
notify:
- Restart Service
rescue:
- name: Create using tinc client
- name: Generate keys with tinc client
command: "tinc -n {{ tinc_netname }} generate-keys {{ tinc_key_size }}"
args:
creates: "/etc/tinc/{{ tinc_netname }}/rsa_key.priv"
Expand All @@ -100,6 +102,11 @@
src: "/etc/tinc/{{ tinc_netname }}/hosts/{{ inventory_hostname | replace('.','_') | replace('-','_') }}"
register: tinc_host_file

# TODO: REMOVE
- name: Show generated files for debugging purposes
debug:
msg: "{{ tinc_host_file['content'] | b64decode }}"

- name: Upload all hosts files on each host
copy:
dest: "/etc/tinc/{{ tinc_netname }}/hosts/{{ item | replace('.','_') | replace('-','_') }}"
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
minversion = 1.8
envlist = ansible-{2.9,latest}-{ring,star,openwrt}
envlist = ansible-{2.9,latest}-{ring,star,openwrt,switch}
skipsdist = true

[testenv]
Expand All @@ -16,3 +16,4 @@ commands =
ring: molecule test []
star: molecule test -s star []
openwrt: molecule test -s openwrt []
switch: molecule test -s switch []