Skip to content

Instantly share code, notes, and snippets.

@mdfranz
Created July 24, 2013 19:58
Show Gist options
  • Save mdfranz/6073985 to your computer and use it in GitHub Desktop.
Save mdfranz/6073985 to your computer and use it in GitHub Desktop.
How to specify hosts in variables for stuff like access control lists
$ ansible-playbook -i hosts -c local access.yaml
PLAY [all] ********************************************************************
GATHERING FACTS ***************************************************************
ok: [127.0.0.1]
TASK: [template src=./access.j2 dest=./access.conf] ***************************
changed: [127.0.0.1]
PLAY RECAP ********************************************************************
127.0.0.1 : ok=2 changed=1 unreachable=0 failed=0
$ cat access.conf
<Directory "/var/www/html/">
order allow,deny
allow from 192.168.1.1
allow from 10.0.0.0/8
</Directory>
$ cat access.j2
<Directory "/var/www/html/">
order allow,deny
{% for h in hosts %}
allow from {{ h }}
{% endfor %}
</Directory>
$ cat access.yaml
---
- hosts: all
vars:
hosts:
- 192.168.1.1
- 10.0.0.0/8
tasks:
- template: src=./access.j2 dest=./access.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment