GithubHelp home page GithubHelp logo

Comments (12)

jdauphant avatar jdauphant commented on August 28, 2024

Hello,

Try with {{ item }}, it could work.
It could be interesting to introduce variables into the template.

Best regards,
Julien

from ansible-role-nginx.

mike-pt avatar mike-pt commented on August 28, 2024

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.

jdauphant avatar jdauphant commented on August 28, 2024

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.

mike-pt avatar mike-pt commented on August 28, 2024

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.

jdauphant avatar jdauphant commented on August 28, 2024

Ok I keep it open

from ansible-role-nginx.

mike-pt avatar mike-pt commented on August 28, 2024

@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.

mike-pt avatar mike-pt commented on August 28, 2024

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.

jdauphant avatar jdauphant commented on August 28, 2024

Sorry, no idea, I do not use as much Ansible

from ansible-role-nginx.

philipwigg avatar philipwigg commented on August 28, 2024

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.

mike-pt avatar mike-pt commented on August 28, 2024

@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.

philipwigg avatar philipwigg commented on August 28, 2024

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.

mike-pt avatar mike-pt commented on August 28, 2024

lol sorry I did not realised that

from ansible-role-nginx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.