community.openwrt.command module – Execute commands on OpenWrt targets

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.command.

Synopsis

  • The community.openwrt.command module runs a command on the remote OpenWrt device.

  • The command is executed directly or through a shell depending on the uses_shell parameter.

  • This module does not support check mode.

Note

This module has a corresponding action plugin.

Parameters

Parameter

Comments

chdir

string

Change into this directory before running the command.

cmd

aliases: raw_params, _raw_params

string / required

The command to execute.

creates

string

A filename or glob pattern.

If it already exists, the command does not run.

executable

string

The shell to use when uses_shell is true.

Default: "/bin/sh"

removes

string

A filename or glob pattern.

If it does not exist, the command does not run.

uses_shell

aliases: _uses_shell

boolean

Whether to execute the command through a shell.

If false, the command is executed directly.

If true, the command is executed through the shell specified in executable.

Choices:

  • false ← (default)

  • true

Attributes

Attribute

Support

Description

check_mode

Support: none

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

diff_mode

Support: none

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

- name: Run a simple command
  community.openwrt.command:
    cmd: uptime

- name: Run a command with arguments
  community.openwrt.command:
    cmd: ls -la /etc

- name: Change directory before running command
  community.openwrt.command:
    cmd: pwd
    chdir: /tmp

- name: Only run if file does not exist
  community.openwrt.command:
    cmd: touch /tmp/myfile
    creates: /tmp/myfile

Return Values

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

Key

Description

cmd

string

The command executed.

Returned: always

Sample: "/usr/bin/uptime"

delta

string

The command execution time.

Returned: always

Sample: "0:00:02.000000"

end

string

The command end time.

Returned: always

Sample: "2025-12-05 10:15:25.000000"

rc

integer

The command return code.

Returned: always

Sample: 0

start

string

The command start time.

Returned: always

Sample: "2025-12-05 10:15:23.000000"

stderr

string

The command standard error.

Returned: always

Sample: ""

stdout

string

The command standard output.

Returned: always

Sample: "Foo foo foo"

Authors

  • Markus Weippert (@gekmihesg)