vmware.vmware_rest.vcenter_vm_guest_filesystem_directories module – Manage directories in the guest operating system of a virtual machine.

Note

This module is part of the vmware.vmware_rest collection (version 5.0.0).

You might already have this collection installed if you are using the ansible package. 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 vmware.vmware_rest.

To use it in a playbook, specify: vmware.vmware_rest.vcenter_vm_guest_filesystem_directories.

New in vmware.vmware_rest 5.0.0

DEPRECATED

Removed in:

version 6.0.0

Why:

This functionality has been replaced by ansible.builtin.file.

Alternative:

Use ansible.builtin.file instead.

Synopsis

  • Create, delete, or move directories within the guest operating system of a running virtual machine.

  • Operations are performed through VMware Tools, so VMware Tools must be installed and running in the guest, and valid guest credentials must be supplied for every action.

  • Use state=create to create a directory, state=createTemporary to create a uniquely named temporary directory, state=delete to remove a directory, and state=move to move or rename a directory.

  • None of the actions are idempotent; each call performs the requested guest operation directly.

Parameters

Parameter

Comments

create_parents

boolean

Whether to create any missing parent directories along the path.

If a failure occurs, some parent directories may be left behind.

When omitted, parent directories are not created.

Used when state=create.

Choices:

  • false

  • true

credentials

dictionary / required

The guest operating system credentials used to authenticate and run the requested operation inside the virtual machine.

Required for every action.

interactive_session

boolean

If true, the operation interacts with the logged-in desktop session in the guest. This requires that the logged-on user matches the user named in credentials.user_name.

Only supported when credentials.type=USERNAME_PASSWORD.

Choices:

  • false

  • true

password

string

The password for the guest account named in credentials.user_name.

Only relevant when credentials.type=USERNAME_PASSWORD.

saml_token

string

The SAML bearer token used to authenticate within the guest.

Only relevant when credentials.type=SAML_BEARER_TOKEN.

type

string

The type of guest credentials being supplied.

USERNAME_PASSWORD authenticates with a guest username and password. Supply credentials.user_name and credentials.password.

SAML_BEARER_TOKEN authenticates with a SAML bearer token obtained from the VMware SSO server, associated with a guest account through a guest alias. Supply credentials.saml_token and optionally credentials.user_name.

Choices:

  • "USERNAME_PASSWORD"

  • "SAML_BEARER_TOKEN"

user_name

string

The guest username to authenticate as.

When credentials.type=USERNAME_PASSWORD, this is the guest account username.

When credentials.type=SAML_BEARER_TOKEN, this is the guest user to associate with the token. If omitted, a guest-dependent mapping determines which guest account is used.

new_path

string

The complete path, in the guest filesystem, to move the directory to, or its new name.

It must not point to an existing directory or an existing file.

Required when state=move.

parent_path

string

The complete path, in the guest filesystem, of the directory in which to create the new temporary directory.

When omitted, a guest-specific default location is used.

Used when state=createTemporary.

path

string

The complete path, in the guest filesystem, of the directory to act on.

When state=create, this is the directory to create.

When state=delete, this is the directory to delete.

When state=move, this is the existing directory to move or rename.

Required when state=create, state=delete, or state=move.

prefix

string

The prefix for the name of the new temporary directory.

Required when state=createTemporary.

recursive

boolean

If true, all files and subdirectories are deleted as well. If false, the directory must be empty for the deletion to succeed.

When omitted, directory contents are not deleted.

Used when state=delete.

Choices:

  • false

  • true

session_timeout

float

Timeout in seconds for the whole operation including connection establishment, request sending, and response.

Default: 300.0

state

string / required

The desired state of the resource.

Use create to perform the create action.

Use createTemporary to perform the createTemporary action.

Use delete to perform the delete action.

Use move to perform the move action.

This module does not support idempotence.

Choices:

  • "create"

  • "createTemporary"

  • "delete"

  • "move"

suffix

string

The suffix for the name of the new temporary directory.

Required when state=createTemporary.

vcenter_hostname

string / required

The hostname or IP address of the vSphere vCenter.

If the value is not specified in the task, the value of environment variable VMWARE_HOST will be used instead.

vcenter_password

string / required

The vSphere vCenter password.

If the value is not specified in the task, the value of environment variable VMWARE_PASSWORD will be used instead.

vcenter_port

integer

The port number of the vSphere vCenter.

If the value is not specified in the task, the value of environment variable VMWARE_PORT will be used instead.

vcenter_rest_log_file

string

Optional path to a log file for HTTP REST interaction.

If the value is not specified in the task, the value of environment variable VMWARE_REST_LOG_FILE will be used instead.

vcenter_username

string / required

The vSphere vCenter username.

If the value is not specified in the task, the value of environment variable VMWARE_USER will be used instead.

vcenter_validate_certs

boolean

Allows connection when SSL certificates are not valid.

Set to false when certificates are not trusted.

If the value is not specified in the task, the value of environment variable VMWARE_VALIDATE_CERTS will be used instead.

Choices:

  • false

  • true ← (default)

vm

string / required

Identifier of the vm to manage.

Must be an identifier (MOID) for a Vm resource.

Notes

Note

  • Generated from vSphere API spec 9.1.0.

  • Compatible with vSphere API 7.0.3.

  • Compatible with vSphere API 8.0.2.

Examples

- name: Create a directory in the guest
  vmware.vmware_rest.vcenter_vm_guest_filesystem_directories:
    vm: vm-1234
    state: create
    path: /tmp/ansible_app
    credentials:
      type: USERNAME_PASSWORD
      user_name: root
      password: guest_password

- name: Create a directory and any missing parent directories
  vmware.vmware_rest.vcenter_vm_guest_filesystem_directories:
    vm: vm-1234
    state: create
    path: /opt/app/config/nested
    create_parents: true
    credentials:
      type: USERNAME_PASSWORD
      user_name: root
      password: guest_password

- name: Create a uniquely named temporary directory
  vmware.vmware_rest.vcenter_vm_guest_filesystem_directories:
    vm: vm-1234
    state: createTemporary
    prefix: ansible_
    suffix: _tmp
    parent_path: /tmp
    credentials:
      type: USERNAME_PASSWORD
      user_name: root
      password: guest_password
  register: temp_dir

- name: Move or rename a directory
  vmware.vmware_rest.vcenter_vm_guest_filesystem_directories:
    vm: vm-1234
    state: move
    path: /tmp/ansible_app
    new_path: /opt/ansible_app
    credentials:
      type: USERNAME_PASSWORD
      user_name: root
      password: guest_password

- name: Delete a directory and all of its contents
  vmware.vmware_rest.vcenter_vm_guest_filesystem_directories:
    vm: vm-1234
    state: delete
    path: /opt/ansible_app
    recursive: true
    credentials:
      type: USERNAME_PASSWORD
      user_name: root
      password: guest_password

Return Values

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

Key

Description

value

any

The raw API response body from the vCenter operation.

When state=createTemporary, this is the complete path of the newly created temporary directory in the guest.

For state=create, state=delete, and state=move the operation returns no content.

Returned: On success

Sample: "/tmp/ansible_abc123_tmp"

Status

  • This module will be removed in version 6.0.0. [deprecated]

  • For more information see DEPRECATED.

Authors

  • Ansible Eco Content Team (@eco-ansible-content)