VMware Aria Automation Tools

 View Only
  • 1.  vRA 8.6 | IF / ELSE statement in YAML with Booleans

    Posted Mar 30, 2022 06:45 PM

    Hello, 

    I am trying to get some assistance with the following. I am using a Boolean 

    inputs:
    app1:
    type: boolean
    title: SQL
    default: false
    app2:
    type: boolean
    title: IIS
    default: false

    I would like to then be able to pass this into an input which will call ansible playbook that will match then the app1 or app2 tittle (SQL or IIS etc) which will be the name of the Ansible playbook in the controller. 

    ------------------------

    Cloud_Ansible_1:
    type: Cloud.Ansible
    properties:

    ----------------------

    playbooks:
    provision:
    - /home/ansible/playbook.yml
    - '${input.app1 == "true" ? "/home/ansible/sql.yaml" : ””}'          ----->  Run the following if the App1 is true . 

    but for some reason the value is not working and instead I am getting an error with:

    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.app1

    Can someone provide some assistance? maybe I am doing something wrong or something needs to be different? 

    Thank you



  • 2.  RE: vRA 8.6 | IF / ELSE statement in YAML with Booleans

    Broadcom Employee
    Posted Mar 31, 2022 04:07 PM

    Hi,

    Not sure what is creating the exact problem but it seems to me that the variable is represented as an ansible variable. On the other hand, check the following blog on achieving it in another way.

    https://www.mobius.co.uk/deeper-look-at-the-vrealize-automation-and-ansible-open-source-integration/

    I know it is not a direct answer to your question, but will let you achieve what you want to do. For the exact problem, I need to test it myself and unfortunately I do not have this setup in my environment.



  • 3.  RE: vRA 8.6 | IF / ELSE statement in YAML with Booleans
    Best Answer

    Posted Apr 01, 2022 02:53 PM

    I wonder if the error might be due to having a null value in there when app1 isn't true?

    Defaulting to a valid-but-empty playbook path might be an option:

    resources:
      Cloud_Ansible_1:
        type: Cloud.Ansible
        properties:
          [...]
          playbooks:
            provision:
              - /home/ansible/playbook.yml
              - '${input.app1 ? "/home/ansible/app1.yml" : "/home/ansible/empty.yml"}'
              - '${input.app2 ? "/home/ansible/app2.yml" : "/home/ansible/empty.yml"}'

    Just a guess though. I don't have access to Ansible in my lab at the moment so I can't test this myself. It works in my head though!



  • 4.  RE: vRA 8.6 | IF / ELSE statement in YAML with Booleans

    Broadcom Employee
    Posted Apr 03, 2022 11:00 AM

    This is currently being reviewed , whether if else is supported under ansible code block or not 



  • 5.  RE: vRA 8.6 | IF / ELSE statement in YAML with Booleans
    Best Answer

    Posted Apr 04, 2022 07:16 PM

    Can you try literal null instead of empty string "" after the colon? (I can't try either as not using Ansible here.)



  • 6.  RE: vRA 8.6 | IF / ELSE statement in YAML with Booleans
    Best Answer

    Broadcom Employee
    Posted Apr 05, 2022 05:14 AM
    inputs:
      App1:
        type: boolean
        Default: false
        title: App1
    resources:
      Ansible:
        type: Cloud.Ansible
        metadata:
          layoutPosition:
            - 0
            - 1
        properties:
          account: eso-ansible
          username: administrator
          password: Dynam1c0ps
          maxConnectionRetries: 20
          playbooks:
            provision:
              - '${input.App1 == true ?  "/root/ansible-playbooks/windows_enableiis.yml" :  ""}'
          osType: windows
          inventoryFile: /root/ansible-playbooks/windowshosts
          groups:
            - win2012
          host: ${resource.AnsibleWindowsVM.*}


    This should work error was occurring since we were passing true in quotes which was making it string ,instead of predefined type of boolean 



  • 7.  RE: vRA 8.6 | IF / ELSE statement in YAML with Booleans

    Broadcom Employee
    Posted Apr 05, 2022 03:20 PM

    Thanks Ankush. This should definitely solve it. Missed that point. After al it is a syntax problem.



  • 8.  RE: vRA 8.6 | IF / ELSE statement in YAML with Booleans

    Posted Apr 05, 2022 04:33 PM

    Thank you all for your assistance!