community.openwrt.uci module – Controls OpenWrt UCI

Note

This module is part of the community.openwrt collection (version 0.5.0).

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install community.openwrt.

To use it in a playbook, specify: community.openwrt.uci.

Synopsis

  • The community.openwrt.uci module is a Ansible wrapper for OpenWrt’s uci.

  • It supports all the command line functionality plus some extra commands.

Note

This module has a corresponding action plugin.

Parameters

Parameter

Comments

autocommit

boolean

Whether to automatically commit changes.

Choices:

  • false ← (default)

  • true

command

aliases: cmd

string

uci command to execute.

The default is set if value is passed, otherwise the default is get.

The get, export, and show states should be factored out of this module into an _info module.

Choices:

  • "absent"

  • "add"

  • "add_list"

  • "batch"

  • "changes"

  • "commit"

  • "del_list"

  • "export"

  • "find"

  • "get"

  • "import"

  • "rename"

  • "reorder"

  • "revert"

  • "section"

  • "set"

  • "show"

config

string

Config part of the key.

If not specified, extracted from key.

aliases: find_by, search

string

Value(s) to match sections against.

Option value to find if option is set. May be list.

Dict of options/values if option is not set. Values may be list.

Lists are compared in order.

Required when command=find or command=section.

keep_keys

aliases: keep

string

Space separated list or list of keys not in value or find to keep when replace=yes.

key

string

The uci key to operate on.

Takes precedence over config, section and option.

If not specified, constructed as config.section.option.

merge

boolean

Whether to merge or replace when command=import.

Choices:

  • false ← (default)

  • true

name

string

New name when command=rename or command=add.

Desired name when command=section. If a matching section is found it is renamed, if not it is created with that name.

option

string

Option part of the key.

If not specified, extracted from key.

replace

boolean

When command=set or command=section, whether to delete all options not mentioned in keep_keys, value or find when set_find=true.

Choices:

  • false ← (default)

  • true

section

string

Section part of the key.

If not specified, extracted from key.

set_find

boolean

When command=section whether to set the options used to search a matching section in the newly created section when no match was found.

Choices:

  • false ← (default)

  • true

type

string

Section type for command=section, command=find and command=add.

If not specified, defaults to the value of section.

unique

boolean

When command=add_list, whether to add the value if it is already contained in the list.

Choices:

  • false ← (default)

  • true

value

string

The value for various commands.

Attributes

Attribute

Support

Description

check_mode

Support: full

Can run in check_mode and return changed status prediction without modifying target.

diff_mode

Support: full

Returns details on what has changed (or possibly needs changing in check_mode), when in diff mode.

platform

Platform: OpenWrt

Target platform for this module.

Examples

# Find a section of type wifi-iface with matching name or matching attributes.
# If not found create it and set the attributes from find.
# Unconditionally set the attributes from value and delete all other options.
- community.openwrt.uci:
    command: section
    config: wireless
    type: wifi-iface
    name: ap0
    find:
      device: radio0
      ssid: My SSID
    value:
      encryption: none
    replace: yes

# Find a matching wifi-iface and delete it.
- community.openwrt.uci:
    command: absent
    config: wireless
    type: wifi-iface
    find:
      ssid: My SSID broken

# Find a matching wifi-iface and delete the options key and encryption.
- community.openwrt.uci:
    command: absent
    config: wireless
    type: wifi-iface
    find:
      ssid: My SSID public
    value:
      - key
      - encryption

# Commit changes and notify.
- community.openwrt.uci:
    cmd: commit
  notify: restart wifi

Return Values

Common return values are documented here, the following are the fields unique to this module:

Key

Description

command

string

Command executed.

Returned: always

Sample: "section"

config

string

Config part of key.

Returned: when given

Sample: "wireless"

option

string

Option part of key.

Returned: when given

Sample: "ssid"

result

string

Output of the uci command.

Returned: always

Sample: "cfg12523"

result_list

list / elements=string

The list form of result.

Returned: when command=get

Sample: ["0.pool.ntp.org", "1.pool.ntp.org"]

section

string

Section part of key.

Returned: when given

Sample: "@wifi-iface[0]"

Authors

  • Markus Weippert (@gekmihesg)