theko2fi.multipass.multipass_vm_exec module – Execute command in a Multipass virtual machine

Note

This module is part of the theko2fi.multipass collection (version 0.3.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 theko2fi.multipass.

To use it in a playbook, specify: theko2fi.multipass.multipass_vm_exec.

New in theko2fi.multipass 0.2.0

Synopsis

  • Executes a command in a Multipass virtual machine.

Parameters

Parameter

Comments

command

string / required

The command to execute.

name

string / required

The name of the virtual machine to execute the command in.

workdir

string

The directory to run the command in.

Examples

- name: Run a simple command
  theko2fi.multipass.multipass_vm_exec:
    name: foo
    command: /bin/bash -c "ls -lah"
  register: result

- name: Print stdout
  ansible.builtin.debug:
    var: result.stdout_lines

- name: Run a simple command in a specific working directory
  theko2fi.multipass.multipass_vm_exec:
    name: foo
    command: "ls -la"
    workdir: /tmp
  register: result

- name: Run a simple command (stderr)
  theko2fi.multipass.multipass_vm_exec:
    name: foo
    command: /bin/bash -c "echo Hello world! && echo Hello world! > /dev/stderr"
  register: result

- name: Print stderr lines
  ansible.builtin.debug:
    var: result.stderr_lines

Return Values

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

Key

Description

stderr

string

The standard error output of the virtual machine command.

Returned: success

stdout

string

The standard output of the virtual machine command.

Returned: success

Authors

  • Kenneth KOFFI (@theko2fi)