Re: [ansible-project] Help me to achive this task

2021-10-14 Thread Stefan Hornburg (Racke)

On 14/10/2021 09:22, Dineshbabu Shankar wrote:

Can any one help me on this


Please define "not working".

Regards

 Racke




On Tue, 12 Oct, 2021, 8:58 pm Dineshbabu Shankar, mailto:shankardineshb...@gmail.com>> wrote:

My requiremnt ,

i need to add the disk to vms in vcenter   by passing
vm name, datastorename , and  disk_size   via csv file ,
with the following condition.
1. datastore which i am providing the csv should be in facts collected from 
vms
2.datastore  free volume is greater than what we requested (disk_size)
3.after taking the required disk_size the datastore should be  greater than 
equal to 20% of the total size of the datastore .

i can achieve this for the single server  but for more than one server i am 
struggling , can any one help me ,

Working one (for one server )
 cat test/diskadditionpre.yaml
---
  - hosts: localhost
    vars_prompt:
      - name: vcentername
        prompt: "Enter the vcenter name"
        private: no
      - name: vcenter_user
        prompt: "Enter the username"
        private: no
      - name: vcenter_password
        prompt: "Enter your password"
      - name: datastore_name
        prompt: "Enter the datastore name "
        private: no
      - name: disk_size
        prompt: "Enter the disksize in GB"


    tasks:
    - name: collecting the vminformation
      vmware_guest_facts:
        validate_certs: no
        hostname: "{{ vcentername }}"
        username: "{{ vcenter_user }}"
        password: "{{ vcenter_password }}"
        datacenter: DFW
        folder: /DFW/vm/Servers/Linux
        name: vmtest1
      delegate_to: localhost
      register: vm_info

    - name: Get the datastores associated with the VM
      set_fact:
         datastorelist: "{{vm_info.instance.hw_files | join (' ')}}"  # 
#converting list into the srting for easy  when condition use#

    - name: checking wheather enter correct datastore
      assert:
       that:
         - "datastore_name in datastorelist"
       success_msg: 'VM has correct Datastore.'
       fail_msg: 'Pls Enter the correct Datastore name '

    - name: Collecting the datastore information
      vmware_datastore_info:
        validate_certs: no
        hostname: '{{ vcentername }}'
        username: '{{ vcenter_user }}'
        password: '{{ vcenter_password }}'
        datacenter_name: DFW
        name: '{{datastore_name}}'
      delegate_to: localhost
      register: datastore_info
      when: " datastore_name in datastorelist " # if the datastorelist 
contains the name datastore_name procees furthur#

    - set_fact: datastore_cap="{{datastore_info.datastores[0].capacity |float / 
1073741824|float }}" # byte to GB converstion
    - set_fact: datastore_free="{{datastore_info.datastores[0].freeSpace |float 
/ 1073741824|float}}"
    - set_fact: 
datastore_used="{{datastore_info.datastores[0].provisioned|filesizeformat(true)}}"
    - set_fact: datastore_buffer="{{datastore_free|float - 
disk_size|float}}"
    - set_fact: datastore_buffer_s="{{(datastore_buffer)|float / ( 
datastore_cap)|float }}"
    - set_fact: datastore_buffer_percentage="{{100*(datastore_buffer_s) 
|float}}"
      when: " datastore_name in datastorelist "

    - name: Checking wheather datastore having enough disk
      assert:
        that:
          - "(datastore_free|float ) > (disk_size|float)"
          - "(datastore_buffer_percentage |float) > (20.0|float)"
        fail_msg: 'Free Disk is lesser than the required disksize'
        success_msg: 'Free Disk is greater than require disksize'

    - name: disk addition should be with either scsi controller with type  
no or controllernumber with type
      vmware_guest_disk:
       validate_certs: no
       hostname: "{{ vcentername }}"
       username: "{{ vcenter_user }}"
       password: "{{ vcenter_password }}"
       datacenter: DFW
       folder: /DFW/vm/Servers/Linux
       name: vmtest1
       disk:
       - size_gb: "{{disk_size}}"
         type: thick
         state: present
         scsi_controller: 2   #required paramater
         scsi_type: 'paravirtual' #required paramater
         datastore: "{{datastore_name}}"
         unit_number: 3 #required paramater
         destroy: no
      when:
        - "(datastore_free|float ) > (disk_size|float)"
        - "( datastore_name) in (datastorelist) "
        - "(datastore_buffer_percentage |float) > (20.0|float)"



NOT working (multiple servers)

---
  - hosts: localhost
    vars_prompt:
      - name: vcentername
        prompt: "Enter the vcenter name"
        private: no
      - name: vcenter_user
        

Re: [ansible-project] Help me to achive this task

2021-10-14 Thread Dineshbabu Shankar
Can any one help me on this


On Tue, 12 Oct, 2021, 8:58 pm Dineshbabu Shankar, <
shankardineshb...@gmail.com> wrote:

> My requiremnt ,
>
> i need to add the disk to vms in vcenter   by passing
> vm name, datastorename , and  disk_size   via csv file ,
>
> with the following condition.
> 1. datastore which i am providing the csv should be in facts collected
> from vms
> 2.datastore  free volume is greater than what we requested (disk_size)
> 3.after taking the required disk_size the datastore should be  greater
> than equal to 20% of the total size of the datastore .
>
> i can achieve this for the single server  but for more than one server i
> am struggling , can any one help me ,
>
> Working one (for one server )
>  cat test/diskadditionpre.yaml
> ---
>   - hosts: localhost
> vars_prompt:
>   - name: vcentername
> prompt: "Enter the vcenter name"
> private: no
>   - name: vcenter_user
> prompt: "Enter the username"
> private: no
>   - name: vcenter_password
> prompt: "Enter your password"
>   - name: datastore_name
> prompt: "Enter the datastore name "
> private: no
>   - name: disk_size
> prompt: "Enter the disksize in GB"
>
>
> tasks:
> - name: collecting the vminformation
>   vmware_guest_facts:
> validate_certs: no
> hostname: "{{ vcentername }}"
> username: "{{ vcenter_user }}"
> password: "{{ vcenter_password }}"
> datacenter: DFW
> folder: /DFW/vm/Servers/Linux
> name: vmtest1
>   delegate_to: localhost
>   register: vm_info
>
> - name: Get the datastores associated with the VM
>   set_fact:
>  datastorelist: "{{vm_info.instance.hw_files | join (' ')}}"  #
> #converting list into the srting for easy  when condition use#
>
> - name: checking wheather enter correct datastore
>   assert:
>that:
>  - "datastore_name in datastorelist"
>success_msg: 'VM has correct Datastore.'
>fail_msg: 'Pls Enter the correct Datastore name '
>
> - name: Collecting the datastore information
>   vmware_datastore_info:
> validate_certs: no
> hostname: '{{ vcentername }}'
> username: '{{ vcenter_user }}'
> password: '{{ vcenter_password }}'
> datacenter_name: DFW
> name: '{{datastore_name}}'
>   delegate_to: localhost
>   register: datastore_info
>   when: " datastore_name in datastorelist " # if the datastorelist
> contains the name datastore_name procees furthur#
>
> - set_fact:  datastore_cap="{{datastore_info.datastores[0].capacity
> |float / 1073741824|float }}" # byte to GB converstion
> - set_fact: datastore_free="{{datastore_info.datastores[0].freeSpace
> |float / 1073741824|float}}"
> - set_fact:
> datastore_used="{{datastore_info.datastores[0].provisioned|filesizeformat(true)}}"
> - set_fact: datastore_buffer="{{datastore_free|float -
> disk_size|float}}"
> - set_fact: datastore_buffer_s="{{(datastore_buffer)|float / (
> datastore_cap)|float }}"
> - set_fact: datastore_buffer_percentage="{{100*(datastore_buffer_s)
> |float}}"
>   when: " datastore_name in datastorelist "
>
> - name: Checking wheather datastore having enough disk
>   assert:
> that:
>   - "(datastore_free|float ) > (disk_size|float)"
>   - "(datastore_buffer_percentage |float) > (20.0|float)"
> fail_msg: 'Free Disk is lesser than the required disksize'
> success_msg: 'Free Disk is greater than require disksize'
>
> - name: disk addition should be with either scsi controller with type
> no or controllernumber with type
>   vmware_guest_disk:
>validate_certs: no
>hostname: "{{ vcentername }}"
>username: "{{ vcenter_user }}"
>password: "{{ vcenter_password }}"
>datacenter: DFW
>folder: /DFW/vm/Servers/Linux
>name: vmtest1
>disk:
>- size_gb: "{{disk_size}}"
>  type: thick
>  state: present
>  scsi_controller: 2   #required paramater
>  scsi_type: 'paravirtual' #required paramater
>  datastore: "{{datastore_name}}"
>  unit_number: 3 #required paramater
>  destroy: no
>   when:
> - "(datastore_free|float ) > (disk_size|float)"
> - "( datastore_name) in (datastorelist) "
> - "(datastore_buffer_percentage |float) > (20.0|float)"
>
>
>
> NOT working (multiple servers)
>
> ---
>   - hosts: localhost
> vars_prompt:
>   - name: vcentername
> prompt: "Enter the vcenter name"
> private: no
>   - name: vcenter_user
> prompt: "Enter the username"
> private: no
>   - name: vcenter_password
> prompt: "Enter your password"
> #  - name: disk_size
> #prompt: "Enter the disksize in GB"
> tasks:
> - name: read csv
>   read_csv:
>path: 

[ansible-project] Help me to achive this task

2021-10-12 Thread Dineshbabu Shankar
My requiremnt , 

i need to add the disk to vms in vcenter   by passing 
vm name, datastorename , and  disk_size   via csv file , 
 
with the following condition.
1. datastore which i am providing the csv should be in facts collected from 
vms 
2.datastore  free volume is greater than what we requested (disk_size)
3.after taking the required disk_size the datastore should be  greater than 
equal to 20% of the total size of the datastore . 

i can achieve this for the single server  but for more than one server i am 
struggling , can any one help me ,

Working one (for one server ) 
 cat test/diskadditionpre.yaml
---
  - hosts: localhost
vars_prompt:
  - name: vcentername
prompt: "Enter the vcenter name"
private: no
  - name: vcenter_user
prompt: "Enter the username"
private: no
  - name: vcenter_password
prompt: "Enter your password"
  - name: datastore_name
prompt: "Enter the datastore name "
private: no
  - name: disk_size
prompt: "Enter the disksize in GB"


tasks:
- name: collecting the vminformation
  vmware_guest_facts:
validate_certs: no
hostname: "{{ vcentername }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
datacenter: DFW
folder: /DFW/vm/Servers/Linux
name: vmtest1
  delegate_to: localhost
  register: vm_info

- name: Get the datastores associated with the VM
  set_fact:
 datastorelist: "{{vm_info.instance.hw_files | join (' ')}}"  # 
#converting list into the srting for easy  when condition use#

- name: checking wheather enter correct datastore
  assert:
   that:
 - "datastore_name in datastorelist"
   success_msg: 'VM has correct Datastore.'
   fail_msg: 'Pls Enter the correct Datastore name '

- name: Collecting the datastore information
  vmware_datastore_info:
validate_certs: no
hostname: '{{ vcentername }}'
username: '{{ vcenter_user }}'
password: '{{ vcenter_password }}'
datacenter_name: DFW
name: '{{datastore_name}}'
  delegate_to: localhost
  register: datastore_info
  when: " datastore_name in datastorelist " # if the datastorelist 
contains the name datastore_name procees furthur#

- set_fact:  datastore_cap="{{datastore_info.datastores[0].capacity 
|float / 1073741824|float }}" # byte to GB converstion
- set_fact: datastore_free="{{datastore_info.datastores[0].freeSpace 
|float / 1073741824|float}}"
- set_fact:  
datastore_used="{{datastore_info.datastores[0].provisioned|filesizeformat(true)}}"
- set_fact: datastore_buffer="{{datastore_free|float - 
disk_size|float}}"
- set_fact: datastore_buffer_s="{{(datastore_buffer)|float / ( 
datastore_cap)|float }}"
- set_fact: datastore_buffer_percentage="{{100*(datastore_buffer_s) 
|float}}"
  when: " datastore_name in datastorelist "

- name: Checking wheather datastore having enough disk
  assert:
that:
  - "(datastore_free|float ) > (disk_size|float)"
  - "(datastore_buffer_percentage |float) > (20.0|float)"
fail_msg: 'Free Disk is lesser than the required disksize'
success_msg: 'Free Disk is greater than require disksize'

- name: disk addition should be with either scsi controller with type  
no or controllernumber with type
  vmware_guest_disk:
   validate_certs: no
   hostname: "{{ vcentername }}"
   username: "{{ vcenter_user }}"
   password: "{{ vcenter_password }}"
   datacenter: DFW
   folder: /DFW/vm/Servers/Linux
   name: vmtest1
   disk:
   - size_gb: "{{disk_size}}"
 type: thick
 state: present
 scsi_controller: 2   #required paramater
 scsi_type: 'paravirtual' #required paramater
 datastore: "{{datastore_name}}"
 unit_number: 3 #required paramater
 destroy: no
  when:
- "(datastore_free|float ) > (disk_size|float)"
- "( datastore_name) in (datastorelist) "
- "(datastore_buffer_percentage |float) > (20.0|float)"



NOT working (multiple servers) 

---
  - hosts: localhost
vars_prompt:
  - name: vcentername
prompt: "Enter the vcenter name"
private: no
  - name: vcenter_user
prompt: "Enter the username"
private: no
  - name: vcenter_password
prompt: "Enter your password"
#  - name: disk_size
#prompt: "Enter the disksize in GB"
tasks:
- name: read csv
  read_csv:
   path: /opt/depot/dinesh/diskaddition.csv
  register: serverlist

- name: vminfo
  vmware_guest_facts:
validate_certs: no
hostname: "{{ vcentername }}"
username: "{{ vcenter_user }}"
password: "{{ vcenter_password }}"
datacenter: DFW
folder: /DFW/vm/Servers/Linux
name: "{{item.servername}}"
  loop: "{{serverlist.list}}"