diff options
author | B Stack <bgstack15@gmail.com> | 2018-02-07 21:38:01 -0500 |
---|---|---|
committer | B Stack <bgstack15@gmail.com> | 2018-02-07 21:38:01 -0500 |
commit | b302a46a5887c087673d66feb967a7b2f94d2133 (patch) | |
tree | 527142bee294c9c4ce0910f8d32bfee18a1674b0 /README.md | |
parent | initial commit (diff) | |
download | vcenter_matrix-b302a46a5887c087673d66feb967a7b2f94d2133.tar.gz vcenter_matrix-b302a46a5887c087673d66feb967a7b2f94d2133.tar.bz2 vcenter_matrix-b302a46a5887c087673d66feb967a7b2f94d2133.zip |
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 44 |
1 files changed, 43 insertions, 1 deletions
@@ -10,8 +10,50 @@ This script prompts for the username and password to the vcenters. Then it itera vi vcenters.txt # add in your vcenter hostnames ./generate.sh +### Output +This script generates a csv and a yaml file containing vcenter name, vm name, and bios uuid. +Examples: + + # vcenter_matrix.csv + vcnorth,prod1,42208510-d3d6-348a-9cb2-8f8ef832a731 + vcnorth,prod2,42101708-7564-645a-5c75-cb54d81a28fd + vcnorth,prod3,4210f2ab-7154-1bd3-be43-89cb59237bc2 + + # vcenter_matrix.yml + vcenter_matrix: + - { vcenter: "vcnorth", hostname: "prod1", uuid: "42208510-d3d6-348a-9cb2-8f8ef832a731" } + - { vcenter: "vcnorth", hostname: "prod2", uuid: "42101708-7564-645a-5c75-cb54d81a28fd" } + - { vcenter: "vcnorth", hostname: "prod3", uuid: "4210f2ab-7154-1bd3-be43-89cb59237bc2" } + +### Using the output +The output files are designed to be useful to determine what vcenter is running any given host. A vmware_guest_facts or any other vmware ansible module needs the vcenter ("hostname") specified, so you have to know it ahead of time. You can take advantage of this generated list with a task: + + # Note: you need the tr upper lower command. + - name: Learn uuid of vm + shell: warn=no dmidecode 2>/dev/null | awk '/UUID:/{print $2}' | tr '[:upper:]' '[:lower:]' + register: this_uuid + changed_when: false + become: yes + + - name: Learn which vcenter is running this host + shell: warn=no grep -E ',{{ ansible_nodename }},' /etc/ansible/configuration/vcenter_matrix/vcenter_matrix.csv | awk -F',' '{print $1}' + register: this_vc_hostname + delegate_to: localhost + changed_when: false + failed_when: this_vc_hostname.stdout_lines | length != 1 + + - name: vmware guest facts + vmware_guest_facts: + hostname: "{{ this_vc_hostname.stdout }}" + username: "{{ vc_username }}" + password: "{{ vc_password }}" + datacenter: "nodatacenterprovided" + validate_certs: no + uuid: "{{ this_uuid.stdout }}" + delegate_to: localhost + register: facts + # Reference ## Weblinks 1. File descript 10 https://unix.stackexchange.com/questions/107800/using-while-loop-to-ssh-to-multiple-servers 2. Web problem with vcenter api is because of escaped characters in variables https://github.com/ansible/ansible/issues/32477 - |