To copy a file to multiple datastores on multiple vCenters, you can modify
your playbook to loop through a list of vCenters and datastores
---
- name: Copy files to multiple datastores on multiple vCenters
hosts: localhost
gather_facts: no
vars_files:
- vcenter_creds.yml
- vars.yml
tasks:
- name: Loop through vCenters
include_tasks: copy_to_datastores.yml
loop: "{{ vcenters }}"
loop_control:
loop_var: vcenter
Create a separate file named copy_to_datastores.yml with the following
content:
---
- name: Copy file to datastore using delegate_to
community.vmware.vsphere_copy:
hostname: "{{ vcenter.hostname }}"
username: "{{ vcenter.username }}"
password: "{{ vcenter.password }}"
src: "{{ src_file }}"
datacenter: "{{ datacenter }}"
datastore: "{{ item }}"
path: "{{ dst_file }}"
validate_certs: no
delegate_to: localhost
run_once: true
loop: "{{ datastores }}"
In your vars.yml, define your vcenters list and datastores list:
---
vcenters:
- hostname: vcenter1.example.com
username: vcenter1_username
password: vcenter1_password
- hostname: vcenter2.example.com
username: vcenter2_username
password: vcenter2_password
# Add more vCenters as needed
datastores:
- datastore1
- datastore2
# Add more datastores as needed
On Friday, June 16, 2023 at 11:19:10 PM UTC-7 Tony Wong wrote:
> any idea how to modify my playbook to copy file to multiple datastores on
> multiple vcenters?
>
> --
> - name: test
> hosts: all
> gather_facts: no
> vars_files:
> - vcenter_creds.yml
> - vars.yml
> #no_log: True
>
> tasks:
> - name: Copy file to datastore using delegate_to
> community.vmware.vsphere_copy:
> hostname: '{{ vcenter_hostname }}'
> username: '{{ vcenter_sso_admin_esg }}'
> password: '{{ vcenter_sso_admin_esg_pass }}'
> src: '{{ src_file }}'
> datacenter: '{{ datacenter }}'
> datastore: '{{ datastore }}'
> path: '{{ dst_file }}'
> validate_certs: no
> delegate_to: localhost
> run_once: true
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/6ecc7352-3340-47f5-852f-c10f346a9650n%40googlegroups.com.