community.vmware.vsphere_file 模块 – 管理 vCenter 数据存储上的文件
注意
此模块是 community.vmware 集合(版本 5.2.0)的一部分。
如果您正在使用 ansible 包,您可能已经安装了这个集合。 它不包含在 ansible-core 中。 要检查是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用:ansible-galaxy collection install community.vmware。
要在 playbook 中使用它,请指定:community.vmware.vsphere_file。
概要
- 管理 vCenter 数据存储上的文件。 
参数
| 参数 | 注释 | 
|---|---|
| vCenter 服务器上保存数据存储的数据中心。 | |
| vCenter 服务器上要将文件推送到的数据存储。 | |
| vSphere vCenter 或 ESXi 服务器的主机名或 IP 地址。 如果未在任务中指定该值,则将使用环境变量  | |
| vSphere vCenter 或 ESXi 服务器的密码。 如果未在任务中指定该值,则将使用环境变量  | |
| vCenter 服务器上数据存储上的文件或目录。 | |
| 将接收所有 HTTPS 请求并转发它们的 HTTP 代理的端口。 如果未在任务中指定该值,则将使用环境变量  | |
| 提供的路径的状态或操作。 如果为  如果为  如果为  如果为  选项 
 | |
| 上传到数据存储的超时时间(秒)。 默认值:  | |
| vSphere vCenter 或 ESXi 服务器的用户名。 如果未在任务中指定该值,则将使用环境变量  | |
| 当 SSL 证书无效时允许连接。 当证书不受信任时,设置为  如果未在任务中指定该值,则将使用环境变量  选项 
 | 
注意事项
注意
- vSphere 文件夹 API 不允许删除目录对象。 
- 所有模块都需要 API 写入权限,因此在免费 ESXi 许可证上不受支持。 
- 所有变量和 VMware 对象名称都区分大小写。 
示例
- name: Create an empty file on a datastore
  community.vmware.vsphere_file:
    hostname: '{{ vhost }}'
    username: '{{ vuser }}'
    password: '{{ vpass }}'
    datacenter: DC1 Someplace
    datastore: datastore1
    path: some/remote/file
    state: touch
  delegate_to: localhost
- name: Create a directory on a datastore
  community.vmware.vsphere_file:
    hostname: '{{ vhost }}'
    username: '{{ vuser }}'
    password: '{{ vpass }}'
    datacenter: DC2 Someplace
    datastore: datastore2
    path: other/remote/file
    state: directory
  delegate_to: localhost
- name: Query a file on a datastore
  community.vmware.vsphere_file:
    hostname: '{{ vhost }}'
    username: '{{ vuser }}'
    password: '{{ vpass }}'
    datacenter: DC1 Someplace
    datastore: datastore1
    path: some/remote/file
    state: file
  delegate_to: localhost
  ignore_errors: true
- name: Delete a file on a datastore
  community.vmware.vsphere_file:
    hostname: '{{ vhost }}'
    username: '{{ vuser }}'
    password: '{{ vpass }}'
    datacenter: DC2 Someplace
    datastore: datastore2
    path: other/remote/file
    state: absent
  delegate_to: localhost
