Comments (12)
Hello,
Try with {{ item }}
, it could work.
It could be interesting to introduce variables into the template.
Best regards,
Julien
from ansible-role-nginx.
Yeah I've tried that but does't work from the playbook, as the "{{ item }}" variable won't be defined, I'm a bit new to ansible but that's the first thing that cross my mind...
Probably the only way to achieve this is really introducing vars in the template as you suggest, might be a nice improvement to the role :)
from ansible-role-nginx.
Don't hesitate to submit a MR, unfortunately I don't have time to do that myself :(
You can also try this syntaxe also (but I think I won't work either)
example.org: |
listen 80;
server_name {{ item }};
from ansible-role-nginx.
Sure, I'll poke around, I wonder if there's some way to dump/see all vars in verbose mode or something...
In alternative I guess I can use global vars and re-use them in the playbook, maybe a dictionary or something, If you don't mind can we keep this open in case I find a solution (for a while ofc)
from ansible-role-nginx.
Ok I keep it open
from ansible-role-nginx.
@jdauphant I've been looking at this again and I was wondering if there would be a way to have example.org: set to "{{site_name}}":
Say one passes a extra var ` ansible-playbook site.yml -e "site_name=example.org"
And then we have (in the site.yml playbook):
nginx_sites:
'{{site_name}}':
- |
listen 80;
server_name {{site_name}} www.{{site_name}};
access_log "{{nginx_log_dir}}/{{site_name}}-access.log";
error_log "{{nginx_log_dir}}/{{site_name}}-error.log";
Something like this would be awesome cause we can have a single playbook to spin up a bunch of nginx-sites by just passing the site_name var
But when I try to do that I get:
failed: [example.org] => (item={{site_name}}) => {"failed": true, "item": "{{site_name}}", "msg": "AnsibleUndefinedVariable: 'dict object' has no attribute u'{#site_name#}'"
I was expecting '{{site_name}}' to use the var value, but it fails with the dic object error, and I honestly don't get why, do you have any idea?
(note that this happen either with {{site_name}} or '{{site_name}}'
from ansible-role-nginx.
Guess this is the issue I'm facing --> ansible/ansible#9008 or at least similar.
My understanding is that ansible recent versions wont' do variable interpolation for "keys" cause some example seemed to indicate this worked before...
The alternative would be using set_fact I guess, but I would prefer a cleaner way, oh well
from ansible-role-nginx.
Sorry, no idea, I do not use as much Ansible
from ansible-role-nginx.
I don't think you can use a variable as a dictionary key.
You can certainly use a variable as the value for your server_name
like you do in your first example but you'd have to define the variable as usual (i.e. in the playbook, or in group_vars, or wherever).
You can probably close this one?
from ansible-role-nginx.
@philipwigg yeah, you're correct and I could never really take the time to maybe find a work around.
Fell free to close
from ansible-role-nginx.
Cheers. I don't think I can close this one as it's not my issue and I'm not an owner.
from ansible-role-nginx.
lol sorry I did not realised that
from ansible-role-nginx.
Related Issues (20)
- Add installation from sources HOT 1
- remove a site is not taken in consideration HOT 2
- Ansible error HOT 1
- Change nginx user HOT 4
- disable default config HOT 5
- Error in handlers/main.yml HOT 1
- issue when adding header parameter with ";" HOT 1
- Does this role need run as root? HOT 1
- amplify.api_key variable does not exist HOT 1
- add_header X-XSS-Protection is causing problems HOT 2
- Nginx didn't start on install
- v2.16 missing on https://galaxy.ansible.com/jdauphant/nginx HOT 1
- Warning, Duplicate When Key HOT 5
- Allow for no default config to be generated HOT 3
- Configuring modules is currently limited to Centos/RHEL only HOT 1
- Missing mime.types file plus /etc/mime.types idea HOT 2
- Adhere to ansible-lint rules HOT 2
- Travis job is still on python 2.7 HOT 2
- Debian 12 (python3) support
- version > v2.21.2 are not avaiable via ansible-galaxy install command
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansible-role-nginx.