benbalter / pi-hole-cloudflared-docker-compose-ansible-caddy

Example configuration for using Pi-Hole, Cloudflared, Docker Compose, Ansible, and Caddy to over-engineer your home network for privacy and security.
https://ben.balter.com/2021/09/01/how-i-re-over-engineered-my-home-network/
MIT License
152 stars 32 forks source link

`nmcli` not working on Raspbian #2

Open pdemarti opened 3 years ago

pdemarti commented 3 years ago

Context

First of all, thank you for your excellent blog and for this automated template! I wasn't aware of several of the techniques and packages you describe -- it was awesome for me to discover Pi-hole, Cloudflare, Caddy and Ansible.

I've been spending a few hours trying to get the step:

Sit back and wait until I have a fully configured PiHole running in about 5-10 minutes.

to work... ;-)

So far, I've learned a lot, and found a few issues and tricks in the ansible config. I hope you don't mind if I address them in separate tickets. As a preview, so far:

nmcli not working out of the box on Raspbian

Symptoms

When running ansible-playbook playbook.yml --inventory hosts.yml, I get:

fatal: [192.168.1.2]: FAILED! => {"changed": false, "msg": "Error: unknown connection 'eth0'.\n", "name": "eth0", "rc": 10}

It appears that nmcli is not working out of the box on Raspbian. See e.g. here.

A potential fix is this gist:

# already done in the playbook
sudo apt update
sudo apt install network-manager

# new steps
sudo apt purge openresolv dhcpcd5
sudo reboot

Steps to reproduce the behavior

  1. Clone this repo.
  2. ssh to a freshly flashed Raspbian 10 Raspberry Pi.
  3. adjust the image and set up the RPi to be reachable by ssh (see below)
  4. ansible-playbook playbook.yml --inventory hosts.yml

Note: Adjustments to fresh image When I flash a new Raspberry image, I always tweak the content of the SD card as it is still in the card reader:

  1. mount the boot and rootfs partitions locally, say in /Volumes (Mac) or /media/$USER/ (Ubuntu); whatever the exact location, below I use $mp;
  2. create wpa_supplicant.conf under $mp/boot/ (see e.g. here)
  3. enable ssh (touch $mp/boot/ssh);
  4. mkdir -p $mp/rootfs/home/pi/.ssh and cat ~/.ssh/id_rsa.pub >> $mp/rootfs/home/pi/.ssh/authorized_keys.
  5. put the SD card in the Raspberry, power it on
  6. find the address that was given by the router
  7. ssh pi@that-address
  8. set a static IP address, see e.g. here.

Expected behavior

I expect nmcli to be operational and work as the ansible playbook intentended.

pdemarti commented 3 years ago

@benbalter : were you able to actually get nmcli to work at all? I've tried quite a few things, no cigar. I put the question to SO, but so far it hasn't prompted much interest...