title: Unable to create 'Azure VM' with Custom Image Using 'Ansible'
body: <p>I am trying to automate the process of updating an image in the scale set. So, I wrote an Ansible playbook to create a VM from a custom image and then, later, make some changes in that VM, capture an image of the said VM and change the image reference in the scale set. But I am getting the following error:</p>
  <pre class="lang-none prettyprint-override"><code>fatal: [localhost]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Error creating or updating virtual machine vmss_update_vm - (InvalidParameter) Parameter 'osProfile' is not allowed.\nCode: InvalidParameter\nMessage: Parameter 'osProfile' is not allowed.\nTarget: osProfile&quot;}
  </code></pre>
  <p>The play looks like this:</p>
  <pre class="lang-yaml prettyprint-override"><code>- name:
    hosts: localhost
    connection: local
    gather_facts: false
    vars:
      resource_group: {{resource_group }}
      shared_gallery_name: linux_build
      shared_image_name: linux_build
      shared_image_version: 0.0.1
      admin_username: ubuntuadmin
      admin_password: Ubuntuadmin@123
      vm_name: vmss_update_vm
      vmss_name: testbuild2
    tasks:
    - name:  Create VM using shared image
      azure_rm_virtualmachine:
        resource_group: &quot;{{ resource_group }}&quot;
        name: &quot;{{ vm_name }}&quot;
        vm_size: Standard_D2s_v3
        managed_disk_type: Standard_LRS
        admin_username: testadmin
        admin_password: Pass123@
        image: 
          id: &quot;/subscriptions/{{subscription_id}}/resourceGroups/{{resource_group}}/providers/Microsoft.Compute/galleries/linux_build/images/linux-build/versions/0.0.1&quot;
          # name: linux-build         
  </code></pre>
  <p>On further research, I found out that I was providing the <code>admin_user</code> and <code>admin_password</code> along with a custom image which is not allowed.</p>
  <p><a href="https://i.stack.imgur.com/eYj5c.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eYj5c.png" alt="Error message description from microsoft" /></a></p>
  <p>So, I removed the <code>admin_user</code> and <code>admin_password</code> and ran the playbook again:</p>
  <pre class="lang-yaml prettyprint-override"><code>- name:
    hosts: localhost
    connection: local
    gather_facts: false
    vars:
      resource_group: {{resource_group }}
      shared_gallery_name: linux_build
      shared_image_name: linux_build
      shared_image_version: 0.0.1
      vm_name: vmss_update_vm
      vmss_name: testbuild2
    tasks:
    - name:  Create VM using shared image
      azure_rm_virtualmachine:
        resource_group: &quot;{{ resource_group }}&quot;
        name: &quot;{{ vm_name }}&quot;
        vm_size: Standard_D2s_v3
        managed_disk_type: Standard_LRS
        admin_username: testadmin
        admin_password: Pass123@
        image: 
          id: &quot;/subscriptions/{{subscription_id}}/resourceGroups/{{resource_group}}/providers/Microsoft.Compute/galleries/linux_build/images/linux-build/versions/0.0.1&quot;
          # name: linux-build           
  </code></pre>
  <p>But after that I am getting the following error:</p>
  <pre class="lang-none prettyprint-override"><code>fatal: [localhost]: FAILED! =&gt; {&quot;changed&quot;: false, &quot;msg&quot;: &quot;Parameter error: admin_username required when creating a virtual machine.&quot;}
  </code></pre>
  <p>Do you have any idea how can I deal with this?</p>