community.general.lxd_profile (8.5.0) — module

Manage LXD profiles

Authors: Hiroaki Nakamura (@hnakamur)

Install collection

Install with ansible-galaxy collection install community.general:==8.5.0


Add to requirements.yml

  collections:
    - name: community.general
      version: 8.5.0

Description

Management of LXD profiles

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# An example for creating a profile
- hosts: localhost
  connection: local
  tasks:
    - name: Create a profile
      community.general.lxd_profile:
        name: macvlan
        state: present
        config: {}
        description: my macvlan profile
        devices:
          eth0:
            nictype: macvlan
            parent: br0
            type: nic
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# An example for creating a profile in project mytestproject
- hosts: localhost
  connection: local
  tasks:
    - name: Create a profile
      community.general.lxd_profile:
        name: testprofile
        project: mytestproject
        state: present
        config: {}
        description: test profile in project mytestproject
        devices: {}
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# An example for creating a profile via http connection
- hosts: localhost
  connection: local
  tasks:
  - name: Create macvlan profile
    community.general.lxd_profile:
      url: https://127.0.0.1:8443
      # These client_cert and client_key values are equal to the default values.
      #client_cert: "{{ lookup('env', 'HOME') }}/.config/lxc/client.crt"
      #client_key: "{{ lookup('env', 'HOME') }}/.config/lxc/client.key"
      trust_password: mypassword
      name: macvlan
      state: present
      config: {}
      description: my macvlan profile
      devices:
        eth0:
          nictype: macvlan
          parent: br0
          type: nic
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# An example for modify/merge a profile
- hosts: localhost
  connection: local
  tasks:
    - name: Merge a profile
      community.general.lxd_profile:
        merge_profile: true
        name: macvlan
        state: present
        config: {}
        description: my macvlan profile
        devices:
          eth0:
            nictype: macvlan
            parent: br0
            type: nic
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# An example for deleting a profile
- hosts: localhost
  connection: local
  tasks:
    - name: Delete a profile
      community.general.lxd_profile:
        name: macvlan
        state: absent
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# An example for renaming a profile
- hosts: localhost
  connection: local
  tasks:
    - name: Rename a profile
      community.general.lxd_profile:
        name: macvlan
        new_name: macvlan2
        state: present

Inputs

    
url:
    default: unix:/var/lib/lxd/unix.socket
    description:
    - The unix domain socket path or the https URL for the LXD server.
    required: false
    type: str

name:
    description:
    - Name of a profile.
    required: true
    type: str

state:
    choices:
    - present
    - absent
    default: present
    description:
    - Define the state of a profile.
    required: false
    type: str

config:
    description:
    - 'The config for the instance (e.g. {"limits.memory": "4GB"}). See U(https://documentation.ubuntu.com/lxd/en/latest/api/#/profiles/profile_get).'
    - If the profile already exists and its "config" value in metadata obtained from GET
      /1.0/profiles/<name> U(https://documentation.ubuntu.com/lxd/en/latest/api/#/profiles/profile_get)
      are different, then this module tries to apply the configurations U(https://documentation.ubuntu.com/lxd/en/latest/api/#/profiles/profile_put).
    - Not all config values are supported to apply the existing profile. Maybe you need
      to delete and recreate a profile.
    required: false
    type: dict

devices:
    description:
    - 'The devices for the profile (e.g. {"rootfs": {"path": "/dev/kvm", "type": "unix-char"}).
      See U(https://documentation.ubuntu.com/lxd/en/latest/api/#/profiles/profile_get).'
    required: false
    type: dict

project:
    description:
    - Project of a profile. See U(https://documentation.ubuntu.com/lxd/en/latest/projects/).
    required: false
    type: str
    version_added: 4.8.0
    version_added_collection: community.general

new_name:
    description:
    - A new name of a profile.
    - If this parameter is specified a profile will be renamed to this name. See U(https://documentation.ubuntu.com/lxd/en/latest/api/#/profiles/profile_post).
    required: false
    type: str

snap_url:
    default: unix:/var/snap/lxd/common/lxd/unix.socket
    description:
    - The unix domain socket path when LXD is installed by snap package manager.
    required: false
    type: str

client_key:
    aliases:
    - key_file
    description:
    - The client certificate key file path.
    - If not specified, it defaults to C($HOME/.config/lxc/client.key).
    required: false
    type: path

client_cert:
    aliases:
    - cert_file
    description:
    - The client certificate file path.
    - If not specified, it defaults to C($HOME/.config/lxc/client.crt).
    required: false
    type: path

description:
    description:
    - Description of the profile.
    type: str

merge_profile:
    default: false
    description:
    - Merge the configuration of the present profile with the new desired configuration,
      instead of replacing it.
    required: false
    type: bool
    version_added: 2.1.0
    version_added_collection: community.general

trust_password:
    description:
    - The client trusted password.
    - You need to set this password on the LXD server before running this module using
      the following command. lxc config set core.trust_password <some random password>
      See U(https://www.stgraber.org/2016/04/18/lxd-api-direct-interaction/)
    - If trust_password is set, this module send a request for authentication before sending
      any requests.
    required: false
    type: str

Outputs

actions:
  description: List of actions performed for the profile.
  returned: success
  sample:
  - create
  type: list
logs:
  description: The logs of requests and responses.
  returned: when ansible-playbook is invoked with -vvvv.
  sample: (too long to be placed here)
  type: list
old_state:
  description: The old state of the profile
  returned: success
  sample: absent
  type: str