VMware Aria Automation Tools

 View Only
  • 1.  How do you create a string that is taken from in input array in a cloud template?

    Broadcom Employee
    Posted Jan 31, 2025 03:25 PM

    We are trying to run an Ansible playbook that will be deploying 1-10 instances of JBoss on a VM, each with a specific name.  We have an input that prompts the requestor for the names, but are not sure how to construct the string that will be used for the provision definition of the ansible-playbook.

    Excerpt from the cloud template:

      jwsInstance:
        type: array
        items:
          type: string
        title: JBOSS Instance Name
        minItems: 1
        maxItems: 10

    ...

          playbooks:
            provision:
              - |-
                /etc/ansible/playbook/middleware/ansible-jws-tomcat-install.yml --extra-vars "${
                  '{' +
                  (length(input.jwsInstance) >= 1 ? '"jboss_jws_instance1_name":"' + input.jwsInstance[0] + '",' : '') +
                  (length(input.jwsInstance) >= 2 ? '"jboss_jws_instance2_name":"' + input.jwsInstance[1] + '",' : '') +
                  (length(input.jwsInstance) >= 3 ? '"jboss_jws_instance3_name":"' + input.jwsInstance[2] + '",' : '') +
                  (length(input.jwsInstance) >= 4 ? '"jboss_jws_instance4_name":"' + input.jwsInstance[3] + '",' : '') +
                  (length(input.jwsInstance) >= 5 ? '"jboss_jws_instance5_name":"' + input.jwsInstance[4] + '",' : '') +
                  (length(input.jwsInstance) >= 6 ? '"jboss_jws_instance6_name":"' + input.jwsInstance[5] + '",' : '') +
                  (length(input.jwsInstance) >= 7 ? '"jboss_jws_instance7_name":"' + input.jwsInstance[6] + '",' : '') +
                  (length(input.jwsInstance) >= 8 ? '"jboss_jws_instance8_name":"' + input.jwsInstance[7] + '",' : '') +
                  (length(input.jwsInstance) >= 9 ? '"jboss_jws_instance9_name":"' + input.jwsInstance[8] + '",' : '') +
                  (length(input.jwsInstance) >= 10 ? '"jboss_jws_instance10_name":"' + input.jwsInstance[9] + '",' : '') +
                  '"jboss_jws_instance_count":' + to_string(length(input.jwsInstance)) +
                  '}'
                }"

    This is the error we get when deploying the VM:

    Unable to validate syntax for Playbook(s). Failed to execute script on host <FQDN> Error: usage: ansible-playbook [-h] [--version] [-v] [--private-key PRIVATE_KEY_FILE]
    [-u REMOTE_USER] [-c CONNECTION] [-T TIMEOUT]
    [--ssh-common-args SSH_COMMON_ARGS]
    [--sftp-extra-args SFTP_EXTRA_ARGS]
    [--scp-extra-args SCP_EXTRA_ARGS]
    [--ssh-extra-args SSH_EXTRA_ARGS]
    [-k | --connection-password-file CONNECTION_PASSWORD_FILE]
    [--force-handlers] [--flush-cache] [-b]
    [--become-method BECOME_METHOD]
    [--become-user BECOME_USER]
    [-K | --become-password-file BECOME_PASSWORD_FILE]
    [-t TAGS] [--skip-tags SKIP_TAGS] [-C] [-D]
    [-i INVENTORY] [--list-hosts] [-l SUBSET]
    [-e EXTRA_VARS] [--vault-id VAULT_IDS]
    [--ask-vault-password | --vault-password-file VAULT_PASSWORD_FILES]
    [-f FORKS] [-M MODULE_PATH] [--syntax-check]
    [--list-tasks] [--list-tags] [--step]
    [--start-at-task START_AT_TASK]
    playbook [playbook ...]
    ansible-playbook: error: unrecognized arguments: jboss_jws_instance2_name:node2 jboss_jws_instance_count:2

    usage: ansible-playbook [-h] [--version] [-v] [--private-key PRIVATE_KEY_FILE]
    [-u REMOTE_USER] [-c CONNECTION] [-T TIMEOUT]
    [--ssh-common-args SSH_COMMON_ARGS]
    [--sftp-extra-args SFTP_EXTRA_ARGS]
    [--scp-extra-args SCP_EXTRA_ARGS]
    [--ssh-extra-args SSH_EXTRA_ARGS]
    [-k | --connection-password-file CONNECTION_PASSWORD_FILE]
    [--force-handlers] [--flush-cache] [-b]



  • 2.  RE: How do you create a string that is taken from in input array in a cloud template?

    Posted Feb 03, 2025 05:06 PM

    instead of using the extra-vars option, we're passing the values into the playbook using the hostVars field. May need to recode your playbook to take in N properties. For example:

          playbooks:
            provision:
              - /Windows_prep/windowsprep.yml
          groups:
            - win
          hostVariables: |
            virtualEnvironment: AWS
            add_domain: ${input.bln_add_domain}
            domain_oupath: ${input.domain_oupath == 'OTHER' ? input.otherOU : input.domain_oupath}
            domain: ${input.domain}
            hostname: ${input.hostname}



    ------------------------------
    Eric Woodford
    www.EricWoodford.com
    ------------------------------



  • 3.  RE: How do you create a string that is taken from in input array in a cloud template?

    Broadcom Employee
    Posted Feb 06, 2025 01:49 PM

    Thank you for the suggestion, but we are still looking for a way of getting the input items added as an parameter that will be appended to the ansible playbook provision command.  Again, we're trying to get the command to be appended with the varying number of input items in the array:

    /etc/ansible/playbook/middleware/ansible-jws-tomcat-install.yml --extra-vars jboss_jws_instance1_name=${input.jwsInstance[0]}, jboss_jws_instance1_name=${input.jwsInstance[2]}...