paramaterized roles - how to do line break or pass args as a list?

13 views
Skip to first unread message

Eric McAlvin

unread,
May 18, 2016, 4:59:48 PM5/18/16
to Ansible Project
I have tried figuring this out for a few hours now and can't get it working..

Does anyone know how to properly format this so the code isn't so wide?

- hosts: 127.0.0.1

  connection: local

  gather_facts: no

  roles:

    - { role: vsphere-guest, vm_name: '{{server1_hostname}}', ip_addr: '{{server1_ip.stdout}}', ip_mask: '{{ip_mask}}', ip_gateway: '{{ip_gateway}}', fqdn: '{{server1_hostname}}', vm_memsize: '{{vm_memsize}}', vm_numcpus: '{{vm_numcpus}}', vcenter_username: '{{ vcenter[vsphere_environment].username }}', vcenter_password: '{{ vcenter[vsphere_environment].password }}', tags: [ 'create_vms', 'create_vm1' ] }



Thanks!

Johannes Kastl

unread,
May 19, 2016, 3:46:17 AM5/19/16
to ansible...@googlegroups.com
On 18.05.16 22:30 Eric McAlvin wrote:
> I have tried figuring this out for a few hours now and can't get it
> working..
>
> Does anyone know how to properly format this so the code isn't so wide?

According to the docs
(https://docs.ansible.com/ansible/YAMLSyntax.html), I would try this:

...
roles:
- role: vsphere-guest
vm_name: '{{server1_hostname}}'
ip_addr: '{{server1_ip.stdout}}'

Can't test at the moment. And I am not sure about the "# Employee
records" example, which the docs show as abbreviated. In the example
there is a string martin in front of the whole dict.

Johannes

signature.asc

Eric McAlvin

unread,
May 19, 2016, 10:54:18 AM5/19/16
to Ansible Project
Your brilliant.  That worked!

Here is the working example:

---


- hosts: 127.0.0.1

  connection: local

  gather_facts: no

  roles:

    - { role: dns-record, start_ip: '{{ vm_start_ip }}', end_ip: '{{ vm_end_ip }}', server_name: '{{ server1_hostname }}' }

  tags:

    - create_dns


- hosts: 127.0.0.1

  connection: local

  gather_facts: no

  vars_files:

    - provision_vault.yml

  pre_tasks:

    - name: get server1 ip

      command: dig +short  '{{ server1_hostname }}'

      register: server1_ip

  roles:

    - role: vsphere-guest

      vm_name: '{{server1_hostname}}'

      ip_addr: '{{server1_ip.stdout}}'

      ip_mask: '{{ip_mask}}'

      ip_gateway: '{{ip_gateway}}'

      fqdn: '{{server1_hostname}}'

      vm_memsize: '{{vm_memsize}}'

      vm_numcpus: '{{vm_numcpus}}'

      vcenter_username: '{{ vcenter[vsphere_environment].username }}'

      vcenter_password: '{{ vcenter[vsphere_environment].password }}'

      tags: [ 'create_vms', 'create_vm1' ]



So much cleaner :)

Thanks again!
Reply all
Reply to author
Forward
0 new messages