virt_net – Manage libvirt network configuration

From Get docs
Ansible/docs/2.7/modules/virt net module


virt_net – Manage libvirt network configuration

New in version 2.0.


Synopsis

  • Manage libvirt networks.

Requirements

The below requirements are needed on the host that executes this module.

  • python >= 2.6
  • python-libvirt
  • python-lxml

Parameters

Parameter Choices/Defaults Comments

autostart

boolean

  • no
  • yes

Specify if a given network should be started automatically on system boot.

command

-

  • define
  • create
  • start
  • stop
  • destroy
  • undefine
  • get_xml
  • list_nets
  • facts
  • info
  • status
  • modify

in addition to state management, various non-idempotent commands are available. See examples. Modify was added in version 2.1

name

- / required

name of the network being managed. Note that network must be previously defined with xml.


aliases: network

state

-

  • active
  • inactive
  • present
  • absent

specify which state you want a network to be in. If 'active', network will be started. If 'present', ensure that network is present but do not change its state; if it's missing, you need to specify xml argument. If 'inactive', network will be stopped. If 'undefined' or 'absent', network will be removed from libvirt configuration.

uri

-

Default:

"qemu:///system"

libvirt connection uri.

xml

-

XML document used with the define command.



Examples

# Define a new network
- virt_net:
    command: define
    name: br_nat
    xml: '{{ lookup("template", "network/bridge.xml.j2") }}'

# Start a network
- virt_net:
    command: create
    name: br_nat

# List available networks
- virt_net:
    command: list_nets

# Get XML data of a specified network
- virt_net:
    command: get_xml
    name: br_nat

# Stop a network
- virt_net:
    command: destroy
    name: br_nat

# Undefine a network
- virt_net:
    command: undefine
    name: br_nat

# Gather facts about networks
# Facts will be available as 'ansible_libvirt_networks'
- virt_net:
    command: facts

# Gather information about network managed by 'libvirt' remotely using uri
- virt_net:
    command: info
    uri: '{{ item }}'
  with_items: '{{ libvirt_uris }}'
  register: networks

# Ensure that a network is active (needs to be defined and built first)
- virt_net:
    state: active
    name: br_nat

# Ensure that a network is inactive
- virt_net:
    state: inactive
    name: br_nat

# Ensure that a given network will be started at boot
- virt_net:
    autostart: yes
    name: br_nat

# Disable autostart for a given network
- virt_net:
    autostart: no
    name: br_nat

Status

Authors

  • Maciej Delmanowski (@drybjed)

Hint

If you notice any issues in this documentation you can edit this document to improve it.


© 2012–2018 Michael DeHaan
© 2018–2019 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.7/modules/virt_net_module.html