Server IP : 85.214.239.14 / Your IP : 18.217.57.160 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /lib/python3/dist-packages/ansible_collections/cisco/intersight/playbooks/ |
Upload File : |
--- # # Get VM hosts and write information to a .csv file # - hosts: localhost connection: local collections: - cisco.intersight gather_facts: false vars: # Create an anchor for api_info that can be used throughout the file api_info: &api_info # if api_key vars are omitted, INTERSIGHT_API_KEY_ID, INTERSIGHT_API_PRIVATE_KEY, # and INTERSIGHT_API_URI environment variables used for API key data api_private_key: "{{ api_private_key | default(omit) }}" api_key_id: "{{ api_key_id | default(omit) }}" api_uri: "{{ api_uri | default(omit) }}" validate_certs: "{{ validate_certs | default(omit) }}" filename: vm_hosts.csv tasks: # Get the VM hosts - name: "Get VM Hosts" intersight_rest_api: <<: *api_info resource_path: /virtualization/VirtualMachines query_params: $select: Name,Inventory $expand: Inventory($expand=Host($select=HypervisorType,Model,Name,Serial)) $top: 1000 return_list: true register: vm_resp # Create file and write results - name: "Create {{ filename }} and write results" file: path: "{{ filename }}" state: absent - lineinfile: path: "{{ filename }}" line: VM,Hypervisor,Model,Hostname,Serial create: true # Only write VMs that have Host information to the .csv file - lineinfile: path: "{{ filename }}" line: "{{ item.Name }},{{ item.Inventory.Host.HypervisorType }},{{ item.Inventory.Host.Model }},{{ item.Inventory.Host.Name }},{{ item.Inventory.Host.Serial }}" loop: "{{ vm_resp.api_response }}" loop_control: label: "{{ item.Name }}" when: item.Inventory.Host is defined