0

I am trying to do a custom install of openedx and I have a bunch of .yml files with environment variables in them inside paths that looks like this

playbooks/roles/<component-name>/defaults/main.yml

Then, while running a playbook that installs all such components, I'm using a command like this

ansible-playbook ./openedx_native.yml -e"@roles/<component-name-1>/defaults/main.yml" -e"@roles/<component-name-2>/defaults/main.yml"

Now I want to be able to use the main.yml files from all components and there are about 20-25 of them, so I'm looking for a way to include them using a wildcard, something like this

ansible-playbook ./openedx_native.yml -e"@roles/*/defaults/main.yml"

This, of course, doesn't work and Ansible throws an error like this

ERROR! the file_name '/var/tmp/configuration/playbooks/roles/*/defaults/main.yml' does not exist, or is not readable

How do I achieve this? Please help!

Gaurav Ojha
  • 1,147
  • 1
  • 15
  • 37
  • 1
    you can use `import_tasks: stuff.yaml` in your playbook using `with_items` on var having list of all components. – error404 Jun 07 '19 at 10:50

2 Answers2

2

An option would be to find the files and include_vars.

  tasks:
    - command: "sh -c 'find {{ playbook_dir }}/roles/*/defaults/main.yml'"
      register: result
    - include_vars:
        file: "{{ item }}"
      loop: "{{ result.stdout_lines }}"
Vladimir Botka
  • 58,131
  • 4
  • 32
  • 63
0

If you have flexibility to change & re-arrange environment variables and its values in /group/all.yaml like environments: - { name: ‘development’, profile: 'small' } - { name: ‘staging’, profile: ‘medium’ } - { name: ‘production’, profile: ‘complex’ }

And then you can use this variable for any task say for example you want to create folder with environment name

    - name: create folders for Environment
  file: 
    path: "{{ target }}/{{ item.name }}"
    state: directory
    mode: 0755
  with_items: "{{ environments }}"
Shubhu
  • 41
  • 5