<h5 dir="auto">ISSUE TYPE</h5>

<ul dir="auto">
<li>Bug Report</li>
</ul>
<h5 dir="auto">COMPONENT NAME</h5>

<p dir="auto">vmware_guest</p>
<h5 dir="auto">ANSIBLE VERSION</h5>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" ansible --version
ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]
"><pre class="notranslate"><code class="notranslate"> ansible --version
ansible 2.3.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
  python version = 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609]

</code></pre></div>
<h5 dir="auto">CONFIGURATION</h5>

<p dir="auto">Standard ansible config, no changes</p>
<h5 dir="auto">OS / ENVIRONMENT</h5>

<p dir="auto">cat /etc/lsb-release<br>
DISTRIB_ID=Ubuntu<br>
DISTRIB_RELEASE=16.04<br>
DISTRIB_CODENAME=xenial<br>
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"</p>
<h5 dir="auto">SUMMARY</h5>

<p dir="auto">Following the example given in  <a href="https://docs.ansible.com/ansible/vmware_guest_module.html" rel="nofollow">https://docs.ansible.com/ansible/vmware_guest_module.html</a>, <code class="notranslate">Create a VM from a template</code>,  I tried to add an extra disk while creating a VM from template. It throws an error.</p>
<h5 dir="auto">STEPS TO REPRODUCE</h5>

<p dir="auto">I tried to use a template to create a VM . The template is a RHEL 7, 64bit one, with 40GB HDD attached and partitioned via LVM.  The code  used is given below .</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  - name: deploy virtual machine from template
    vmware_guest:
      hostname: &quot;{{ vcenter_hostname }}&quot;
      username: &quot;{{ vcenter_username }}&quot;
      password: &quot;{{ vcenter_password }}&quot;
      name: &quot;{{ vm_name }}&quot;
      validate_certs: &quot;false&quot;
      cluster: &quot;{{ vcenter_cluster }}&quot;
      datacenter: &quot;{{ vcenter_datacenter }}&quot;
      folder: &quot;/dev/VMs&quot;
      state: poweredon
      #guest_id: rhel7Guest
      disk:
        - size_gb: 40
          type: thin
         datastore: &quot;{{ datastore }}&quot;
         # autoselect_datastore: True
        - size_gb: 150
          type: thin
          datastore: &quot;{{ datastore }}&quot;
          #autoselect_datastore: True
      hardware:
        memory_mb: &quot;4096&quot;
        num_cpus: &quot;2&quot;
        scsi: paravirtual
      networks:
        - name: &quot;{{ vm-vlan }}&quot;
          ip: 192.168.051
          netmask: 255.255.255.0          
      template: &quot;{{ vm_template }}&quot;
    delegate_to: &quot;localhost&quot;
    register: &quot;deploy&quot;

"><pre class="notranslate"><code class="notranslate">  - name: deploy virtual machine from template
    vmware_guest:
      hostname: "{{ vcenter_hostname }}"
      username: "{{ vcenter_username }}"
      password: "{{ vcenter_password }}"
      name: "{{ vm_name }}"
      validate_certs: "false"
      cluster: "{{ vcenter_cluster }}"
      datacenter: "{{ vcenter_datacenter }}"
      folder: "/dev/VMs"
      state: poweredon
      #guest_id: rhel7Guest
      disk:
        - size_gb: 40
          type: thin
         datastore: "{{ datastore }}"
         # autoselect_datastore: True
        - size_gb: 150
          type: thin
          datastore: "{{ datastore }}"
          #autoselect_datastore: True
      hardware:
        memory_mb: "4096"
        num_cpus: "2"
        scsi: paravirtual
      networks:
        - name: "{{ vm-vlan }}"
          ip: 192.168.051
          netmask: 255.255.255.0          
      template: "{{ vm_template }}"
    delegate_to: "localhost"
    register: "deploy"


</code></pre></div>

<h5 dir="auto">EXPECTED RESULTS</h5>

<p dir="auto">Expected to create a VM with 2 HDDs,  40GB and  150GB HDDs</p>
<h5 dir="auto">ACTUAL RESULTS</h5>

<p dir="auto">Fails. with error</p>

<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="fatal: [localhost -&gt; localhost]: FAILED! =&gt; {&quot;changed&quot;: true, &quot;failed&quot;: true, &quot;msg&quot;: &quot;A specified parameter was not correct: spec.location.host&quot;}"><pre class="notranslate"><code class="notranslate">fatal: [localhost -&gt; localhost]: FAILED! =&gt; {"changed": true, "failed": true, "msg": "A specified parameter was not correct: spec.location.host"}
</code></pre></div>
<p dir="auto">If I omit the disk option and its variables, the VM is created with the default 40GB HDD and in the same datastore where the template is stored.</p>
<p dir="auto">From <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/X-Cli/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/X-Cli">@X-Cli</a> on 2015-08-15T16:56:46Z</p>
<h5 dir="auto">ISSUE TYPE</h5>
<p dir="auto">Bug Report</p>
<h5 dir="auto">COMPONENT NAME</h5>
<p dir="auto">lxc_container module</p>
<h5 dir="auto">ANSIBLE VERSION</h5>
<p dir="auto"><code class="notranslate">container_config</code> is parsed as a python dict by the ansible <strong>lxc_container module</strong>, at least in current stable version 1.9.</p>
<h5 dir="auto">SUMMARY</h5>
<p dir="auto"><code class="notranslate">container_config</code> is parsed as a Python dict by the ansible <strong>lxc_container module</strong>, at least in current stable version 1.9.</p>
<p dir="auto"><a href="https://github.com/ansible/ansible-modules-extras/blob/stable-1.9/cloud/lxc/lxc_container.py">https://github.com/ansible/ansible-modules-extras/blob/stable-1.9/cloud/lxc/lxc_container.py</a><br>
Lines 1442 to 1444 :</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="container_config=dict(
  type='str'
),        "><pre class="notranslate"><span class="pl-s1">container_config</span><span class="pl-c1">=</span><span class="pl-en">dict</span>(
  <span class="pl-s1">type</span><span class="pl-c1">=</span><span class="pl-s">'str'</span>
),        </pre></div>
<p dir="auto">Python dict are <em>unordered</em>, which may lead to <strong>corrupted config files</strong>. For instance, config directives for LXC network follow <em>a specific order</em>, which is overlooked by the module when the config file is written on disk.</p>
<p dir="auto">As such, the following playbook excerpt</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="  tasks:
    - include_vars: ../vars/lxc_config.yml
    - include_vars: ../globals.yml
    - name: &quot;Create LXC&quot;
      become: yes
      become_method: sudo
      lxc_container: 
        name: &quot;{{ lxc_name }}&quot;
        state: stopped
        lxc_path: /var/lib/lxc
        template: ubuntu
        container_config:
          - &quot;lxc.network.type = veth&quot;
          - &quot;lxc.network.name = internet&quot;
          - &quot;lxc.network.ipv4 = {{ internet_ip }}&quot;
          - &quot;lxc.network.link = internet_br&quot;
          - &quot;lxc.network.flags = up&quot;
          - &quot;lxc.network.type = veth&quot;
          - &quot;lxc.network.name = local&quot;
          - &quot;lxc.network.ipv4 = {{ local_ip }}&quot;
          - &quot;lxc.network.link = local_br&quot;
          - &quot;lxc.network.flags = up&quot;
          - &quot;lxc.network.type = veth&quot;
          - &quot;lxc.network.name = admin&quot;
          - &quot;lxc.network.ipv4 = {{ admin_ip }}&quot;
          - &quot;lxc.network.ipv4.gateway = {{ admin_gateway }}&quot;
          - &quot;lxc.network.link = admin_br&quot;
          - &quot;lxc.network.flags = up&quot;"><pre class="notranslate"><code class="notranslate">  tasks:
    - include_vars: ../vars/lxc_config.yml
    - include_vars: ../globals.yml
    - name: "Create LXC"
      become: yes
      become_method: sudo
      lxc_container: 
        name: "{{ lxc_name }}"
        state: stopped
        lxc_path: /var/lib/lxc
        template: ubuntu
        container_config:
          - "lxc.network.type = veth"
          - "lxc.network.name = internet"
          - "lxc.network.ipv4 = {{ internet_ip }}"
          - "lxc.network.link = internet_br"
          - "lxc.network.flags = up"
          - "lxc.network.type = veth"
          - "lxc.network.name = local"
          - "lxc.network.ipv4 = {{ local_ip }}"
          - "lxc.network.link = local_br"
          - "lxc.network.flags = up"
          - "lxc.network.type = veth"
          - "lxc.network.name = admin"
          - "lxc.network.ipv4 = {{ admin_ip }}"
          - "lxc.network.ipv4.gateway = {{ admin_gateway }}"
          - "lxc.network.link = admin_br"
          - "lxc.network.flags = up"
</code></pre></div>
<p dir="auto">results in the following broken LXC config file</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="# Network configuration
lxc.network.type = veth
lxc.network.type  =  veth
lxc.network.flags = up
lxc.network.flags  =  up
lxc.network.link = lxcbr0
lxc.network.link  =  admin_br
lxc.network.link  =  local_br
lxc.network.link  =  internet_br
lxc.network.hwaddr = 00:16:3e:f1:f5:8e
lxc.network.name  =  internet
lxc.network.name  =  admin
lxc.network.name  =  local
lxc.network.ipv4  =  172.31.0.1
lxc.network.ipv4  =  192.168.0.1
lxc.network.ipv4  =  10.0.0.1
lxc.network.ipv4.gateway  =  192.168.0.254"><pre class="notranslate"><code class="notranslate"># Network configuration
lxc.network.type = veth
lxc.network.type  =  veth
lxc.network.flags = up
lxc.network.flags  =  up
lxc.network.link = lxcbr0
lxc.network.link  =  admin_br
lxc.network.link  =  local_br
lxc.network.link  =  internet_br
lxc.network.hwaddr = 00:16:3e:f1:f5:8e
lxc.network.name  =  internet
lxc.network.name  =  admin
lxc.network.name  =  local
lxc.network.ipv4  =  172.31.0.1
lxc.network.ipv4  =  192.168.0.1
lxc.network.ipv4  =  10.0.0.1
lxc.network.ipv4.gateway  =  192.168.0.254
</code></pre></div>
<p dir="auto">As you can see, parsing in a dict also deduplicates some crucial config lines, which have to be duplicated in a valid LXC config file.</p>
<p dir="auto">Being completely new to Ansible (this was my very first playbook <em>sigh</em>), I am not sure if there is a workaround (except maybe using a templated config file and avoiding <code class="notranslate">container_config</code> altogether). Still, if the <code class="notranslate">container_config</code> could be handled as an ordered YAML sequence, I believe this could solve the problem.</p>
<p dir="auto">Thank you.</p>
<p dir="auto">Copied from original issue: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="101189793" data-permission-text="Title is private" data-url="https://github.com/ansible/ansible-modules-extras/issues/836" data-hovercard-type="issue" data-hovercard-url="/ansible/ansible-modules-extras/issues/836/hovercard" href="https://github.com/ansible/ansible-modules-extras/issues/836">ansible/ansible-modules-extras#836</a></p>