Skip to content

Instantly share code, notes, and snippets.

@gmaurice
Last active March 31, 2020 20:35
Show Gist options
  • Save gmaurice/b7358742f853f53c79cb8417e5af553a to your computer and use it in GitHub Desktop.
Save gmaurice/b7358742f853f53c79cb8417e5af553a to your computer and use it in GitHub Desktop.
load nginx_vhosts array from files
** playbook-test.yml
- hosts: all
gather_facts: no
vars:
nginx_vhosts: []
tasks:
- include_tasks: load-vhosts-conf.yml
vars:
vhost_file: '{{ item }}'
with_filetree: files/vhosts
- debug: var=nginx_vhosts
** ./load-vhosts-conf.yml
---
- name: 'load {{ vhost_file.path }}'
include_vars:
file: "{{ vhost_file.src }}"
name: vhost
- set_fact:
nginx_vhosts: "{{ nginx_vhosts + [ vhost ] }}"
** files/vhosts/a.yml
---
name: a
** files/vhosts/b.yml
---
name: b
=========RUN==RUN==RUN==RUN==RUN==RUN==RUN==RUN===================
$ ansible-playbook -i 'localhost,' playbook-test.yml 03/31/20 - 10:30
PLAY [all] *********************************************************************************************************************************************************************************************************************************
TASK [include_tasks] ***********************************************************************************************************************************************************************************************************************
included: /Users/germain.maurice/code/home/load-vhosts-conf.yml for localhost
included: /Users/germain.maurice/code/home/load-vhosts-conf.yml for localhost
TASK [load b.yml] **************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [set_fact] ****************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [load a.yml] **************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [set_fact] ****************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [debug] *******************************************************************************************************************************************************************************************************************************
ok: [localhost] =>
vhosts:
- name: b
- name: a
PLAY RECAP *********************************************************************************************************************************************************************************************************************************
localhost : ok=7 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment