如何使用剧本将.iso文件复制到VMware数据存储区

时间:2019-05-12 06:47:49

标签: ansible vmware

Ansible写作中的新功能,请您帮我将ISO文件复制到VMware数据存储中 据我了解,我无法直接从网络共享中获取文件,对吗?

所以我使用了net_get模块,然后将其复制到数据存储区

我到目前为止所做的:

品种:

---
vdatacenter: xxx
vdatastore: xxx
vcenter: xxx
vsrc: "\\nas\dir\file.iso"
vdst: "\datastore_folder\"
get_dst: "/tmp/"
vcenter_user: xxx
vcenter_pass: xxx

复制剧本:

- hosts: localhost
  connection: local
  tasks:
    - name: include vars
      include_vars:
        dir: group_vars

    - name: Copy to vCenter
      local_action:
        module: vsphere_copy
        host: '{{ vcenter }}'
        login: '{{ vcenter_user }}'
        password: '{{ vcenter_pass }}'
        src: '{{vsrc}}'
        datacenter: '{{vdatacenter}}'
        datastore: '{{vdatastore}}'
        path: '{{vdst}}'

获取剧本:

- hosts: localhost
  connection: local
  tasks:
    - name: include vars
      include_vars:
        dir: group_vars

    - name: Copy to source
      local_action:
        module: net_get
        src: '{{vsrc}}'
        dst: '{{get_dst}}'
        ansible_network_os: eos

1 个答案:

答案 0 :(得分:0)

我成功使用了: vsphere_copy – Copy a file to a vCenter datastore

- vsphere_copy:
    host: "{{ vcenter }}"
    login: "{{ vcenter_user }}"
    password: "{{ vcenter_pass }}"
    src: "{{ vsrc }}"
    datacenter: "{{ vdatacenter }}"
    datastore: "{{ vdatastore }}"
    path:  "{{ vdst}}"
  delegate_to: localhost

在vSphere 6.5.0.13000上测试