Playbooks to a new Lilik
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
923 B

  1. #!/bin/sh
  2. # wrapper for conditional setting of uci config
  3. # compare http://wiki.openwrt.org/doc/techref/uci
  4. # TODO: add more docs, see http://docs.ansible.com/developing_modules.html
  5. # parameters are command, key, value
  6. source ${1}
  7. unquoted_key="$(echo $key | sed -e s/\'//g)"
  8. unquoted_value="$(echo $value | sed -e s/\'//g)"
  9. # test if we need to apply a change
  10. case $command in
  11. 'set')
  12. [ "$(uci get "$unquoted_key")" = "$value" ]
  13. changed=$?
  14. ;;
  15. 'add_list')
  16. uci get "$unquoted_key" 2>/dev/null |grep -q "$value"
  17. changed=$?
  18. ;;
  19. esac
  20. if [ $changed -eq 0 ]
  21. then
  22. echo -n '{"changed": false}'
  23. else
  24. if [ -z "${_ansible_check_mode}" -o "${_ansible_check_mode}" = "False" ]
  25. then
  26. logger uci $(uci "${command}" ${unquoted_key}="${unquoted_value}")
  27. fi
  28. echo -n '{"changed": true, "msg": "executed uci '${command}' '${unquoted_key}'='${value}'"}'
  29. fi