Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

[Question] - add upstream servers using inventory #142

Open
dandanknight opened this issue Nov 28, 2016 · 1 comment
Open

[Question] - add upstream servers using inventory #142

dandanknight opened this issue Nov 28, 2016 · 1 comment
Labels

Comments

@dandanknight
Copy link

Hi, I'm a relative newbie to Ansible, and would like to be able to dynamically add my upstream servers based upon the API servers defined in my Ansible inventory. I'm trying to deploy Nginx as a load balancer. My question is, I don't seem to use with_items in a playbook, so what would be the recommended way of adding this config?

Many thanks

@ei-grad
Copy link
Contributor

ei-grad commented Nov 29, 2016

Put your api servers into api group in inventory, and then specify something like this in your load balancer vars:

nginx_sites:
  api:
  - |
    listen 80;
    server_name example.com;
    location / {
      proxy_pass http://api/;
    }

nginx_configs:
  upstream:
  - |
    upstream api {
      {% for host in groups['api'] %}
      server {{ hostvars[host].ansible_eth0.ipv4.address }};
      {% endfor %}
    }

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants