├── README.md ├── sshoff.json ├── domains.json ├── dcgit.json ├── dnsservers.json ├── backup.json ├── disable-vcsa-ssh-api.yml ├── create-backup-vcsa-api.yml ├── set-vcsa-dns-servers-api.yml ├── set-vcsa-domain-search-api.yml └── new-datacenter-api.yml /README.md: -------------------------------------------------------------------------------- 1 | # vSphere-6.5-API-Playbook-Examples -------------------------------------------------------------------------------- /sshoff.json: -------------------------------------------------------------------------------- 1 | { 2 | "enabled": true 3 | } 4 | -------------------------------------------------------------------------------- /domains.json: -------------------------------------------------------------------------------- 1 | { 2 | "domain": "student.lab" 3 | } 4 | -------------------------------------------------------------------------------- /dcgit.json: -------------------------------------------------------------------------------- 1 | { 2 | "spec": { 3 | "folder": "datacenter-21", 4 | "name": "fluttershy" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /dnsservers.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "mode": "is_static", 4 | "servers": [ 5 | "192.168.1.10" 6 | ] 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /backup.json: -------------------------------------------------------------------------------- 1 | { 2 | "piece": { 3 | "location_user": "ansible", 4 | "location_password": "P@ssw0rd", 5 | "location": "192.168.1.77:/home/ansible/backups", 6 | "location_type": "SCP" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /disable-vcsa-ssh-api.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | become: no 4 | 5 | tasks: 6 | - name: vcenter login 7 | uri: 8 | url: https://cloudvc.student.lab/rest/com/vmware/cis/session 9 | force_basic_auth: yes 10 | method: POST 11 | user: administrator@vsphere.local 12 | password: P@ssw0rd 13 | status_code: 200 14 | validate_certs: no 15 | register: login 16 | 17 | - name: disable ssh 18 | uri: 19 | url: https://cloudvc.student.lab/rest/appliance/access/ssh 20 | force_basic_auth: yes 21 | method: PUT 22 | body_format: json 23 | body: "{{ lookup('file','sshoff.json') }}" 24 | validate_certs: no 25 | headers: 26 | Cookie: "{{login.set_cookie}}" 27 | -------------------------------------------------------------------------------- /create-backup-vcsa-api.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | become: no 4 | 5 | tasks: 6 | - name: vcenter login 7 | uri: 8 | url: https://cloudvc.student.lab/rest/com/vmware/cis/session 9 | force_basic_auth: yes 10 | method: POST 11 | user: administrator@vsphere.local 12 | password: P@ssw0rd 13 | status_code: 200 14 | validate_certs: no 15 | register: login 16 | 17 | - name: set dns servers 18 | uri: 19 | url: https://cloudvc.student.lab/rest/appliance/recovery/backup/validate 20 | force_basic_auth: yes 21 | method: POST 22 | body_format: json 23 | body: "{{ lookup('file','backup.json') }}" 24 | validate_certs: no 25 | headers: 26 | Cookie: "{{login.set_cookie}}" 27 | -------------------------------------------------------------------------------- /set-vcsa-dns-servers-api.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | become: no 4 | 5 | tasks: 6 | - name: vcenter login 7 | uri: 8 | url: https://cloudvc.student.lab/rest/com/vmware/cis/session 9 | force_basic_auth: yes 10 | method: POST 11 | user: administrator@vsphere.local 12 | password: P@ssw0rd 13 | status_code: 200 14 | validate_certs: no 15 | register: login 16 | 17 | - name: set dns servers 18 | uri: 19 | url: https://cloudvc.student.lab/rest/appliance/networking/dns/servers 20 | force_basic_auth: yes 21 | method: PUT 22 | body_format: json 23 | body: "{{ lookup('file','dnsservers.json') }}" 24 | validate_certs: no 25 | headers: 26 | Cookie: "{{login.set_cookie}}" 27 | -------------------------------------------------------------------------------- /set-vcsa-domain-search-api.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | become: no 4 | 5 | tasks: 6 | - name: vcenter login 7 | uri: 8 | url: https://cloudvc.student.lab/rest/com/vmware/cis/session 9 | force_basic_auth: yes 10 | method: POST 11 | user: administrator@vsphere.local 12 | password: P@ssw0rd 13 | status_code: 200 14 | validate_certs: no 15 | register: login 16 | 17 | - name: set domain search 18 | uri: 19 | url: https://cloudvc.student.lab/rest/appliance/networking/dns/domains 20 | force_basic_auth: yes 21 | method: POST 22 | body_format: json 23 | body: "{{ lookup('file','domains.json') }}" 24 | validate_certs: no 25 | headers: 26 | Cookie: "{{login.set_cookie}}" 27 | -------------------------------------------------------------------------------- /new-datacenter-api.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | become: no 4 | 5 | tasks: 6 | - name: vcenter login 7 | uri: 8 | url: https://yourvc.fqdn.foo/rest/com/vmware/cis/session 9 | force_basic_auth: yes 10 | method: POST 11 | user: yourusername@fqdn.foo 12 | password: '{{ passvc }}' 13 | status_code: 200 14 | validate_certs: no 15 | vars: 16 | passvc: !vault | 17 | $ANSIBLE_VAULT;1.1;AES256 18 | 66303936363465353562613363333436633835356663653736346635623065393134653636613231 19 | 6534363633653836346236548694654655313861333131630a386630393636376436326261623564 20 | 3138633833613466350a613365386333623165333232313139396134633430393164326136363536 21 | 65616637316535356136316264623365386566303663313664663530656136636365633034343865 22 | 3962 23 | register: login 24 | 25 | - name: create data center 26 | uri: 27 | url: https://yourvc.fqdn.foo/rest/vcenter/datacenter 28 | force_basic_auth: yes 29 | method: POST 30 | body_format: json 31 | body: "{{ lookup('file','dcgit.json') }}" 32 | validate_certs: no 33 | headers: 34 | Cookie: "{{login.set_cookie}}" 35 | --------------------------------------------------------------------------------