/etc/netplan can't be edited using yq

83 views Asked by At

I am running a script to setup master node of kubernetes in an ubuntu VM And this is the error i am getting

 sudo yq -i /etc/netplan/01-network-manager-all.yaml network.ethernets.enp0s3.dhcp4 false
Error: open /etc/netplan/01-network-manager-all.yaml: permission denied

This is the shell script i am running with source master.sh

Reference: https://mohewedy.medium.com/install-kubernetes-cluster-in-virtual-machines-the-easy-way-337ef0c4e37f

# master.sh
# find most updated version at: https://github.com/mhewedy/vermin/tree/master/etc/samples-provision/k8s

# HW requirements: 2 CPUS 2 RAM
# OS: Ubuntu focal
set -ex

#should be $(lsb_release -cs) but it appears it is not working on focal yet
docker_ubuntu_release=bionic
k8s_version=1.18.0

# Set hostname and disable swap
sudo hostnamectl set-hostname "$(hostname -I | awk '{print $1}')"
echo "export PS1=\"\[\e[1;35m\]\u\[\033[m\]@\[\e[1;92m\]$(hostname -I | awk '{print $1}')\[\033[m\]:\w \$ \"" >>~/.bashrc

sudo swapoff -a && sudo sed -i 's/\/swap/#\/swap/g' /etc/fstab

## Fix IP Addr
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys CC86BB64
sudo add-apt-repository ppa:rmescandon/yq -y
sudo apt-get update -y
snap remove yq && snap install yq --classic
sudo yq --help
sudo chmod 777 /etc/netplan/01-network-manager-all.yaml
chattr -i /etc/netplan/01-network-manager-all.yaml
sudo netplan apply

// This is the line of failures

sudo yq  -i /etc/netplan/01-network-manager-all.yaml network.ethernets.enp0s3.dhcp4 false
sudo yq  -i /etc/netplan/01-network-manager-all.yaml network.ethernets.enp0s3.addresses[+] "$(hostname -I | awk '{print $1}')/24"
sudo yq  -i /etc/netplan/01-network-manager-all.yaml network.ethernets.enp0s3.gateway4 "$(hostname -I | cut -d "." -f 1-3).1"
sudo yq  -i /etc/netplan/01-network-manager-all.yaml network.ethernets.enp0s3.nameservers.addresses[+] 8.8.8.8
sudo yq  -i /etc/netplan/01-network-manager-all.yaml network.ethernets.enp0s3.nameservers.addresses[+] 8.8.4.4
sudo netplan apply
sleep 1
############# install docker & k8s

// and rest of the script

0

There are 0 answers