VMware Cloud Community
paul_xtravirt
Expert
Expert
Jump to solution

vRA8 with Ansible - playbook selection

The following yaml works fine until I introduce the use of an input to select a playbook to execute. Without this everything works fine. The playbook itself is working fine as well. I have tried multiple iterations of the syntax and for the life of me always end up with the same error at deployment time. Can anyone confirm that in vRA8.9, the use of if/else yaml logic is supported within an Ansible block? I'm starting to think it isn't or if it was has regressed to an earlier 'error' state in this release.

So to confirm, the problem statement is the following line:

- '${input.ansible_role == "web" ? /etc/ansible/windows-iis-setup.yml : /etc/ansible/empty.yml}'

 

Error is as follows:

The only playbook run options supported are playbook level variables (Specified by -e OR --extra-vars). Please correct the following playbooks specified with unsupported options: ${input.ansible_role

 

Full YAML as follows:

formatVersion: 1
inputs:
  ansible_role:
    type: string
    title: Ansible Role
    enum:
      - windows
      - web
resources:
  Cloud_Ansible_1:
    type: Cloud.Ansible
    properties:
      host: ${resource.Cloud_vSphere_Machine_1.*}
      osType: windows
      account: aproans1003.automationpro.lan
      username: admin
      password: B4nananM@n!
      maxConnectionRetries: 30
      groups:
        - ${input.ansible_role}
      playbooks:
        provision:
          - /etc/ansible/common-windows-setup.yml
          - '${input.ansible_role == "web" ? /etc/ansible/windows-iis-setup.yml : /etc/ansible/empty.yml}'
  Cloud_vSphere_Machine_1:
    type: Cloud.vSphere.Machine
    properties:
      image: win2k22stdui
      cpuCount: 1
      totalMemoryMB: 8192
      storage:
        constraints:
          - tag: storage:cluster-gold
      networks:
        - network: ${resource.Cloud_vSphere_Network_1.id}
      tags:
        - key: ansible-role
          value: ${input.ansible_role}
  Cloud_vSphere_Network_1:
    type: Cloud.vSphere.Network
    properties:
      networkType: existing
      constraints:
        - tag: network.type:public

If you found this helpful, please consider awarding some points
Tags (3)
Reply
0 Kudos
1 Solution

Accepted Solutions
hawks76
Enthusiast
Enthusiast
Jump to solution

I ran into the same issue.  What i did was pass some hostVariables to identify extra software and then added code in the main yml file to install IIS if the variable had a certain value.

Design Blueprint YAML for hostVariables

 

hostVariables: |
        vm_env: ${input.environment}
        servertype: ${input.servertype}
        sc: ${resource.WebApp_VM.sc}

 

 

 Ansible code (i use roles):

 

- role: IIS
      when:
      - sc == "IIS"

 

 

If you aren't familiar with roles, i suggest taking a look.  It significantly simplified my setup by putting all the logic for install in Ansible instead of trying to muddle through YAML logic.

View solution in original post

3 Replies
hawks76
Enthusiast
Enthusiast
Jump to solution

I ran into the same issue.  What i did was pass some hostVariables to identify extra software and then added code in the main yml file to install IIS if the variable had a certain value.

Design Blueprint YAML for hostVariables

 

hostVariables: |
        vm_env: ${input.environment}
        servertype: ${input.servertype}
        sc: ${resource.WebApp_VM.sc}

 

 

 Ansible code (i use roles):

 

- role: IIS
      when:
      - sc == "IIS"

 

 

If you aren't familiar with roles, i suggest taking a look.  It significantly simplified my setup by putting all the logic for install in Ansible instead of trying to muddle through YAML logic.

paul_xtravirt
Expert
Expert
Jump to solution

Thanks, I had thought about this approach but was hoping to go down the original route. Out of curiosity, how do you deal with adding a host into multiple groups within ansible from vRA? The groups section seems to suffer with the same issue (ignoring expressions)!

If you found this helpful, please consider awarding some points
Reply
0 Kudos
hawks76
Enthusiast
Enthusiast
Jump to solution

I haven't tried dynamic groups with ansible yet.  I can tinker with it and see how it plays out.

Reply
0 Kudos