0

I have a playbook that is running some roles supplied by a vendor that I don't want to modify. There is a variable being defined in the 'role defaults' (roles/jira_config/default/main.yml) that I want to keep the value of and add onto from my 'play vars'. Normal variable precedence means that my 'play vars' definition overwrites the 'role defaults'. How can I combine the two?

jira.yml

  vars:
    atl_catalina_opts: >-
      -myAdditionA
      -myAdditionB

  roles:
    - role: jira_config

roles/jira_config/default/main.yml

atl_catalina_opts_extra: >-
  -something1
  -something2

As it stands, the value for atl_catalina_opts ends up

"atl_catalina_opts": "myAdditionA myAdditionB"

Whereas I want a combination of the two (order doesn't matter)

"atl_catalina_opts": "something1 something2 myAdditionA myAdditionB"

I've tried something like

  vars:
    atl_catalina_opts: >-
      -{{ atl_catalina_opts }}
      -myAdditionA
      -myAdditionB

but that throws an unhandled exception.

Again, I don't want to modify anything in the jira_config role because that is being supplied by the vendor. Also, that role is the one using the variable so I can't do any tricks like creating another variable that combines the 'play vars' and 'role defaults'. Also, I don't want to search the vendor role for the atl_catalina_opts and add them into my 'play vars'. At some point in the future the vendor may update the role and I don't want to search for changes the vendor has made each time there is an update.

shepster
  • 339
  • 3
  • 13
  • 1
    The feature you are trying to re-implement was once known as `hash_behavior=merge` in ansible.cfg and has been deprecated and removed because it was causing way too many problems. As an entry point to the subject and workarrounds, you can see [this github issue](https://github.com/ansible/ansible/issues/73089). A solution is also proposed in [this SO post](https://stackoverflow.com/questions/65389059/deprecation-of-hash-behavior-merge-in-ansible-2-13) – Zeitounator Feb 03 '23 at 10:01

0 Answers0