Skip to content

Commit

Permalink
Added secondary ip address
Browse files Browse the repository at this point in the history
Signed-off-by: simonmicro <simon@simonmicro.de>
  • Loading branch information
simonmicro committed Oct 17, 2024
1 parent 9787e0c commit dcee0b6
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*secret*
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ As the very first step, you have to install your own key onto the machines (hope
```bash
ssh-copy-id user@ctreffosXX
```
Then take a look into the `hosts` file, which details the specific group membership of the machines. It is strongly recommended to add the `secondary_address` property to the new device, as we have seen mDNS failures way too often. If you use this, you have to assign your own machine a static address inside the `10.13.37.0/24` subnet.

## Preperation
Create a file `secrets.source` and fill it with the following content:
```bash
export WIFI_SSID=<set-your-value-here>
export WIFI_PASSWORD=<set-your-value-here>
```
...then source it:
```bash
. envsetup.source # to configure which inventory to use
ansible -m ping all # just to make you can reach them all
Expand Down
1 change: 1 addition & 0 deletions envsetup.source
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export ANSIBLE_STRATEGY=free
export ANSIBLE_NOCOWS=True
export ANSIBLE_INVENTORY=$(pwd)/hosts
export ANSIBLE_FORKS=99
source secrets.source
16 changes: 15 additions & 1 deletion hosts
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
ctreffos[00:09]

; The secondary network is an additional ipv4 address assigned with the activation of the devices wlan.
; You may specify a static IPv4 with the secondary_address-parameter. AFTER a sucessful provisioning
; of the playbook, you may then override the address Ansible uses by setting the ansible_host parameter.
ctreffos00 secondary_address=10.13.37.100 ansible_host=ctreffos00.lan
ctreffos01 secondary_address=10.13.37.101 ansible_host=ctreffos01.lan
ctreffos02 secondary_address=10.13.37.102 ansible_host=10.13.37.102
ctreffos03 secondary_address=10.13.37.103 ansible_host=ctreffos03.lan
ctreffos04 secondary_address=10.13.37.104 ansible_host=ctreffos04.lan
ctreffos05 secondary_address=10.13.37.105 ansible_host=ctreffos05.lan
ctreffos06 secondary_address=10.13.37.106 ansible_host=ctreffos06.lan
ctreffos07 secondary_address=10.13.37.107 ansible_host=ctreffos07.lan
ctreffos08 secondary_address=10.13.37.108 ansible_host=ctreffos08.lan
ctreffos09 secondary_address=10.13.37.109 ansible_host=ctreffos09.lan

[vscodium]
ctreffos[00:09]

Expand All @@ -10,7 +24,7 @@ ctreffos[00:09]
ctreffos[00:09]

[pixelflut_2024]
ctreffos[00:09]
; ctreffos[00:09]

[all:vars]
ansible_user=user
8 changes: 6 additions & 2 deletions roles/common/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
- name: Enable avahi-daemon service and reload it
systemd:
ansible.builtin.systemd:
name: avahi-daemon
enabled: yes
enabled: true
state: reloaded
- name: Restart network-manager
ansible.builtin.systemd:
name: NetworkManager
state: restarted
36 changes: 36 additions & 0 deletions roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,39 @@
creates: /etc/timeshift/timeshift.json
register: check_status
failed_when: check_status.rc > 1 # 1 means no snapshots
cmd: "timeshift --scripted --snapshot-device /dev/mapper/{{ inventory_hostname }}--vg-root --list"
creates: /etc/timeshift/timeshift.json
register: check_status
failed_when: check_status.rc > 1 # 1 means no snapshots
- name: Install WiFi connection profile (with secondary address)
community.general.nmcli:
type: wifi
conn_name: by-ansible
# conn_reload: true # my Ansible is too old...
ifname: wlp4s0
ssid: "{{ lookup('env', 'WIFI_SSID') }}"
wifi_sec:
key-mgmt: wpa-psk
psk: "{{ lookup('env', 'WIFI_PASSWORD') }}"
ip4:
- "{{ secondary_address }}/24"
method4: auto
autoconnect: true
state: present
when: secondary_address is defined
notify: Restart network-manager
- name: Install WiFi connection profile
community.general.nmcli:
type: wifi
conn_name: by-ansible
# conn_reload: true # my Ansible is too old...
ifname: wlp4s0
ssid: "{{ lookup('env', 'WIFI_SSID') }}"
wifi_sec:
key-mgmt: wpa-psk
psk: "{{ lookup('env', 'WIFI_PASSWORD') }}"
method4: auto
autoconnect: true
state: present
when: not (secondary_address is defined)
notify: Restart network-manager

0 comments on commit dcee0b6

Please sign in to comment.