Giter VIP home page Giter VIP logo

ansible-windows's People

Contributors

gregsowell avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

ansible-windows's Issues

disk expansion

Good stuff,

I built on it a little, my issue is that this part fails everytime:

Everything else works but this part, which of course I need.

I get the following error:

{
  "module_stdout": "",
  "module_stderr": "/bin/sh: line 1: powershell: command not found\n",
  "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
  "rc": 127,
  "_ansible_no_log": null,
  "changed": false
}
  - name: Connect to windows host and expand the drive
    ansible.windows.win_powershell:
      script: |
        # Variable specifying the drive you want to extend
        $drive_letter = "C"

        # Script to get the partition sizes and then resize the volume
        $size = (Get-PartitionSupportedSize -DriveLetter $drive_letter)
        Resize-Partition -DriveLetter $drive_letter -Size $size.SizeMax
---
- name: vm disk expansion
  hosts: localhost
  become: false
  gather_facts: false

  tasks:
  - name: Get all disks from existing VM
    vmware_guest_disk_info:
      validate_certs: False
      datacenter: '{{ data_center }}'
      name: '{{ vm_name  }}'
    register: existing_disk

  - name: Get Backing datastore for desired disk id
    set_fact:
      disk_zero_datastore: "{{ item.value.backing_datastore }}"
    with_dict: "{{ existing_disk.guest_disk_info }}"
    when: item.key == '0'
  
  - debug:
      msg: "{{ disk_zero_datastore }}"
    when: disk_zero_datastore is defined

  - name: Get scsi controller type
    set_fact:
      scsi_type: "{{ item.value.controller_type }}"
    with_dict: "{{ existing_disk.guest_disk_info }}"
    when: item.key == '0'

  - debug:
      msg: '{{ scsi_type }}'
    when: scsi_type is defined


  - name: Get Unit Number
    set_fact:
      unit_number: "{{ item.value.unit_number }}"
    with_dict: "{{ existing_disk.guest_disk_info }}"
    when: item.key == '0'

  - debug:
      msg: '{{ unit_number }}'
    when: unit_number is defined


  - name: Get Disk + 30%
    set_fact:
      disc_size: "{{ item.value.capacity_in_kb|int *13/10| round(2, 'floor')|int }}"
    with_dict: "{{ existing_disk.guest_disk_info }}"
    when: item.key == '0'
  
  - debug:
      msg: '{{ disc_size }}'
    when: disc_size is defined

  - name: Connect to VMWare and shutdown guest
    community.vmware.vmware_guest:
      validate_certs: no
      datacenter: "{{ data_center }}"
      name: "{{ vm_name }}"
      state: shutdownguest
    delegate_to: localhost
    failed_when: vm_shutdown.instance.hw_power_status != 'poweredOff' and vm_shutdown.changed == false
    register: vm_shutdown

  - name: Wait 15 seconds
    ansible.builtin.pause:
      seconds: 15

  - name: Connect to VMWare and resize disk on VM
    community.vmware.vmware_guest_disk:
      validate_certs: no
      datacenter: "{{ data_center }}"
      name: "{{ vm_name }}"
      disk:
        - size_kb: "{{ disc_size|int }}"
          state: present
          unit_number: "{{ unit_number }}"
          scsi_controller: 0
          scsi_type: "{{ scsi_type }}"
    delegate_to: localhost
    register: disk_facts

  - name: Connect to VMWare and boot up guest
    community.vmware.vmware_guest:
      validate_certs: no
      name: "{{ vm_name }}"
      state: poweredon
    delegate_to: localhost
#    register: disk_facts

  - name: Wait 300 seconds, but only start checking after 15 seconds
    wait_for_connection:
      delay: 15
      timeout: 300
  
  - name: Extend disk to 100%

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.