Conditional parameters to vmware_guest

17 views
Skip to first unread message

Enzo

unread,
Aug 24, 2018, 3:43:28 PM8/24/18
to Ansible Project
Hi,

sorry if I continue with newbie questions.
I have my playbook for create vm from template

- name: Clone a VM from Template and customize
  vmware_guest:
    hostname: 192.168.1.209
    username: user
    password: pass
    validate_certs: no
    datacenter: datacenter1
    cluster: cluster
    name: '{{ guest_vm }}'
    template: '{{ template_name }}'
    networks:
    - name: '{{ vmnetwork }}'
      ip: '{{ ip_address }}'
      netmask: '{{ ip_netmask }}'
      gateway: '{{ ip_gateway }}'
      domain: '{{ dns_domain }}'
      dns_servers:
      - 192.168.1.1
      - 192.168.1.2
  delegate_to: localhost

awx take variables from survey, arg
vmnetwork is taken from multichoice.
I want set all others parameters with conditional and not take it from survey. For example in meta language.

if
vmnetwork == "blue" then
ip_address = 192.168.10.XXX
ip_netmask = 192.168.10.1
dns_domain = "blue.com"
dns_server = [ ip1, ip2]
else if
vmnetwork == "red" then
ip_address = 192.168.11.XXX
ip_netmask = 192.168.11.1
dns_domain = "red.com"
dns_server = [ ip1, ip2]
....
and so on
....
end if

Which is the best way for do it in ansible 2.6?
I see this example and should be good for me

# style 1 using filter
- set_fact:
      tomcat_value: "{{ (filepath == '/var/opt/tomcat_1') | ternary(tomcat_1_value, tomcat_2_value) }}"
# style 2
- set_fact:
    tomcat_value: "{{ tomcat_1_value if (filepath == '/var/opt/tomcat_1') else tomcat_2_value }}"


but I see also this example

tasks:
  - name: "shut down CentOS 6 and Debian 7 systems"
    command: /sbin/shutdown -t now
    when: (ansible_distribution == "CentOS" and ansible_distribution_major_version == "6") or
          (ansible_distribution == "Debian" and ansible_distribution_major_version == "7")

Can I set more network: and for each set a when: '{{ vmnetwork }}' == "XXXX" ?

Thank you for your suggestions
Enzo

Reply all
Reply to author
Forward
0 new messages