├── README.md ├── handlers └── main.yml ├── library └── uci └── meta └── main.yml /README.md: -------------------------------------------------------------------------------- 1 | openwrt-uci 2 | =========== 3 | 4 | setting of uci config keys on openwrt systems. this is just the 5 | library module so that other openwrt roles can dependend on it. 6 | 7 | check out [https://github.com/lefant/ansible-openwrt] for an example on 8 | how it can be used. 9 | 10 | compare: [http://wiki.openwrt.org/doc/uci] and [http://wiki.openwrt.org/doc/techref/uci] 11 | 12 | Requirements 13 | ------------ 14 | 15 | must be kept minimal as this is supposed to run on openwrt embedded 16 | systems. in particular we try get by with plain POSIX shell, using 17 | neither python nor bash in any way. lua could be an option as that 18 | seems to be the openwrt scripting language of choice. 19 | 20 | License 21 | ------- 22 | 23 | BSD 24 | 25 | Author Information 26 | ------------------ 27 | 28 | Fabian Linzberger, [http://e.lefant.net/] 29 | 30 | 31 | 32 | [https://github.com/lefant/ansible-openwrt]: https://github.com/lefant/ansible-openwrt 33 | [http://wiki.openwrt.org/doc/uci]: http://wiki.openwrt.org/doc/uci 34 | [http://wiki.openwrt.org/doc/techref/uci]: http://wiki.openwrt.org/doc/techref/uci 35 | [http://e.lefant.net/]: http://e.lefant.net/ 36 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for openwrt-uci 3 | - name: uci commit 4 | raw: uci commit 5 | -------------------------------------------------------------------------------- /library/uci: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # wrapper for conditional setting of uci config 3 | # compare http://wiki.openwrt.org/doc/techref/uci 4 | 5 | # TODO: add more docs, see http://docs.ansible.com/developing_modules.html 6 | 7 | # parameters are command, key, value 8 | source ${1} 9 | 10 | unquoted_key="$(echo $key | sed -e s/\'//g)" 11 | unquoted_value="$(echo $value | sed -e s/\'//g)" 12 | 13 | # test if we need to apply a change 14 | case $command in 15 | 'set') 16 | [ "$(uci get "$unquoted_key")" = "$value" ] 17 | changed=$? 18 | ;; 19 | 'add_list') 20 | uci get "$unquoted_key" 2>/dev/null |grep -q "$value" 21 | changed=$? 22 | ;; 23 | esac 24 | 25 | if [ $changed -eq 0 ] 26 | then 27 | echo -n '{"changed": false}' 28 | else 29 | if [ -z "${_ansible_check_mode}" -o "${_ansible_check_mode}" = "False" ] 30 | then 31 | logger uci $(uci "${command}" ${unquoted_key}="${unquoted_value}") 32 | fi 33 | echo -n '{"changed": true, "msg": "executed uci '${command}' '${unquoted_key}'='${value}'"}' 34 | fi 35 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Fabian Linzberger 4 | description: library for setting of uci config keys on openwrt systems 5 | license: BSD 6 | min_ansible_version: 1.7 7 | platforms: [] 8 | # - Openwrt 9 | # versions: 10 | # - 14.07 11 | categories: 12 | - system 13 | dependencies: [] 14 | --------------------------------------------------------------------------------