Azure / Ansible

Ansible Solution Template on Azure
MIT License
7 stars 10 forks source link

Cannot create image from VM #25

Open Marwen-TAALLAH opened 1 year ago

Marwen-TAALLAH commented 1 year ago

I'm trying to create an azure Vm, install some softwares on it and then create an image from it. Obviously, the VM needs to be generalized in order to able to create an image from it but creating a generalized VM dosen't allow installing softwares on it so the solution I found is to create the VM (not generalized), install softwares then generalize it and create the image:

`- name: Create hardened vm based on azure Ubuntu {{ os }}-{{arch}} azure_rm_virtualmachine: resource_group: '{{ env }}-{{ location }}-test' name: '{{ env }}-{{ os }}-{{arch}}-{{ language }}'

state: running

# generalized: yes
os_type: Linux
ssh_password_enabled: no
ssh_public_keys:
  - path: /home/radmin/.ssh/authorized_keys
    key_data: ssh-rsa .....
admin_username: radmin  
network_interfaces: '{{ env }}-ni-application-{{ os }}-{{arch}}-{{ language }}'
managed_disk_type: Standard_LRS
image:
  offer: 0001-com-ubuntu-server-focal
  publisher: Canonical
  sku: 20_04-lts-gen2
  version: latest
tags:
  env: '{{ env }}'
  language: '{{ language }}'
  os: '{{ os }}'
  arch: '{{arch}}'
public_ip_allocation_method: Static
vm_size: Standard_DS2_v2

register: application_instances

- name: Stop VM before it can be generalized and image captured azure_rm_virtualmachine: resource_group: '{{ env }}-{{ location }}-test' name: '{{ env }}-{{ os }}-{{arch}}-{{ language }}' started: no - name: Generalize VM azure_rm_virtualmachine: resource_group: '{{ env }}-{{ location }}-test' name: '{{ env }}-{{ os }}-{{arch}}-{{ language }}' generalized: true - name: Create an image from a virtual machine azure_rm_image: resource_group: '{{ env }}-{{ location }}-test' name: '{{env}}_{{ os }}_{{ arch }}_{{ language }}' source: '{{ env }}-{{ os }}-{{arch}}-{{ language }}' ` The VM is created, but it fails in the last task with this error: **Error creating image - (OperationNotAllowed) The operation 'Create Image' requires the Virtual Machine to be Generalized** As if the **Generalize VM** task doesn't work (it doesn't throw an error !!) Any thoughts?