1

We want to keep the configuration of two Ansible Automation Platform (AAP) v2 clusters in sync. For this we want to use the Ansible Collection ansible.controller. In a playbook, the export module should be used to selectively export e.g. job_templates and import them to the AAP test cluster using the import module. But only with templates that start with e.g. LNX_.

We've tried using * as a wildcard, but it doesn't work.

Is there a way to use wildcards at this point, or another clever solution?

  - name: "Get all from {{ vault_controller_host_prd_aap23 }}"
    export:
      controller_host:     "{{ vault_controller_host_prd_aap23 }}"
      validate_certs:       False
      controller_username: "{{ vault_controller_host_prd_aap23_username }}"
      controller_password: "{{ vault_controller_host_prd_aap23_password }}"
        projects:            "LNX*"
        job_templates:       "LNX*"
        credentials:         "LNX*"
      register: command_output
U880D
  • 8,601
  • 6
  • 24
  • 40
Isabella
  • 21
  • 2

1 Answers1

0

I understand that you like to use export module – export resources from Automation Platform Controller in order to download the JSON definitions of job_templates.

Is there a way to use wildcards at this point?

As far as I know, no. This is because the modules in question are just wrapper for the Ansible Tower REST API and do not support a ?search= parameter currently. You may also have a look into export.py and import.py.

or another clever solution?

You would need several tasks and multiple calls against the Controller. First List Job Templates, second post-process or filter the result set, than, gather the Job Templates which have the properties in question.

Further reading which might help in this case, How to schedule deletion of unused template?


An other option might be to use directly REST API calls via the uri module and as already described before but together with the ?search=LNX_ option

Searching Use the search query string parameter to perform a case-insensitive search within all designated text fields of a model.

# Test
curl --silent --user ${ACCOUNT}:${PASSWORD} https://${TOWER_URL}/api/v2/job_templates/?search=LNX_ --write-out "\n%{http_code}\n"
# Export
curl --silent --user ${ACCOUNT}:${PASSWORD} https://${TOWER_URL}/api/v2/job_templates/?search=LNX_ | jq .

will result into the expected output, a wildcard will not be necessary.

U880D
  • 8,601
  • 6
  • 24
  • 40