Hi,
I'm trying to deploy Apache with virtualhosts and their aliases and
directories. In order to do so I've setup vars host_vars, Apache vhost config
template and task file. With this setup I can create complete config per
virtualhost, but I can't figure out how to call the var within task to create
the directory.
host_vars/myhost example with two virtualhosts:
---
apache_vhosts:
- server_name:
www.example.com
doc_root: "/var/www/
www.example.com/html"
server_admin: "
webm...@example.com"
alias:
- { name: wiki, path: /var/www/
www.example.com/wiki }
- { name: blog, path: /var/www/
www.example.com/blog }
vhost_dir:
- "/usr/local/share/custom_app1"
- "/usr/local/share/custom_app2"
- server_name:
other.example.com
doc_root: "/var/www/
other.example.com/html"
server_admin: "
webm...@example.com"
alias:
- { name: blah, path: /var/www/
other.example.com/html }
- { name: duh, path: /var/www/
other.example.com/duh }
dirs:
- "/usr/local/share/custom_app1"
- "/usr/local/share/custom_app2"
roles/apache/templates/vhost_conf.j2 example snippet (this works OK):
---
{% if item.vhost_dir is defined %}
{% for d in item.vhost_dir %}
<Directory "{{ d }}">
AllowOverride All
Options -Indexes FollowSymLinks
Order allow,deny
Allow from all
</Directory>
{% endfor %}
{% endif %}
roles/apache/tasks/main.yml 3 examples (I've tried all sorts of combinations,
nothing works):
---
- name: create additional vhost dirs
file: path={{ item.vhost_dir }} state=directory group=apache mode=0755
with_items: apache_vhosts
when: apache_vhosts is defined
- name: create additional vhost dirs
file: path={{ item.apache_vhosts.vhost_dir }} state=directory
group=apache mode=0755
with_items: apache_vhosts
when: apache_vhosts is defined
- name: create additional vhost dirs
file: path={{ item }} state=directory group=apache mode=0755
with_items: apache_vhosts.vhost_dir
when: apache_vhosts is defined
Ansible either skips the task or reports it done, but the directory isn't
created. I guess this is probably YAML issue and I'm trying to do something
impossible?
Regards,
Martin