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

Consider refactoring with ucode #47

Open
Hurricos opened this issue Aug 7, 2022 · 0 comments
Open

Consider refactoring with ucode #47

Hurricos opened this issue Aug 7, 2022 · 0 comments

Comments

@Hurricos
Copy link

Hurricos commented Aug 7, 2022

Hi there,

After trying to come up with a playbook solution to ensure only the wifi-ifaces I've created exist, I've found that ansible-openwrt's remote-only use of UCI is pretty restrictive. It would be easier to deal with configuration state if we could manage some of it locally using e.g. set_fact, but since uci output is hard to parse, that goes out of the window without some rather nasty Python.

We could fix this with Lua's UCI bindings, but even cleaner than that would be ucode, which has bindings for UCI (among other things) already in-place.

The only drawback I can see for now is availability -- as it stands ucode is only pre-installed on 22.03, and isn't yet being compiled or distributed for 21.02, 19.07, etc.

An example snippet of ucode dumping /etc/config/wireless to JSON would be:

require("uci");

cursor = global.modules.uci.cursor();
cursor.load("wireless");

printf("%.J\n", cursor.get_all("wireless"));

This can be run e.g. as

$ ucode -e 'require("uci"); cursor=global.modules.uci.cursor(); cursor.load("wireless"); printf("%.J\n", cursor.get_all("wireless"));'
{
	"radio0": {
		".anonymous": false,
		".type": "wifi-device",
		".name": "radio0",
		".index": 0,
		"type": "mac80211",
		"path": "ffe0a000.pcie/pcia000:02/a000:02:00.0/a000:03:00.0",
		"band": "5g",
		"htmode": "VHT80",
		"channel": "48",
		"country": "US",
		"disabled": "0"
	},
:
	"cfg063579": {
		".anonymous": true,
		".type": "wifi-iface",
		".name": "cfg063579",
		".index": 5,
		"ifname": "netgear2",
		"mode": "ap",
		"device": "radio0",
		"network": "lan",
		"ssid": "NETGEAR52",
		"encryption": "psk2",
		"key": "xxx",
		"disabled": "0"
	}
}

I can use snippets of ucode to feed playbooks for now, but you may want to consider refactoring using ucode to make maintenance easier, at least once it's officially available.

Thanks for your time :^)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant