Managing nginx reverse proxy using salt

148 views
Skip to first unread message

Pier B.

unread,
May 17, 2017, 10:57:55 AM5/17/17
to Salt-users
Hi,

Looks like I am not able to find a solution to a not-so-complex problem :

I have a application server, let's say web server to which client are connecting through a reverse proxy (nginx). So for each app server I must add a small block to my nginx/conf.d/app.proxy config file.
In this block I mainly needs a location and a proxy_pass, this proxy_pass IS the internal name of the app server and the location should be computed from this app server name (with some exception, but I am not even that far).

I am provisioning app server through salt-cloud on our private proxmox, using reactor I am able to configure each and every details from the app server.
I firts thought it would be easy to add the corresponding block to the nginx config file, but finally I am not able to do this :(

The master plan is to simply add a state to the already existing orchestration; this state would just push the block to the nginx by using the data that are already available in this orchestrate state ... For this I tried to use the followong but could not make it works :

{% set vm_name = salt.pillar.get('vm_name') %}
...
[ many others states before, already validated ]
...
# Add vm_name config to proxy(ies)
orchestrate_add_client_to_proxy
:
  salt
.state:
   
- tgt: 'nginx-slave.tld'
   
- sls:
     
- role.proxy.add_client_proxy
   
- pillar:
        tgt_client_name
: {{ vm_name }}

In the above example I am trying to pass the client name (the sever newly created, in this very orchestration actually) by using the vm_name
which I got from the reactor state as :
acd_orch:
  runner
.state.orchestrate:
   
- mods: orch.acd
   
- pillar:
        vm_name
: {{ data.name }}

This allow me to dynamically get the vm name that is being created and use that name as a target (very usual I guess) inside the orchestration state as shown above.

Then "fort de tout cela" I tried to use that vm_name again when calling the state responsible to add the required block to nginx config, but that was unfortunate.

Has anyone a solution for this ? How can I pass an arg / kwarg / pillar data to a state and then how to use it inside this target state ?

I am sure it is not complex but I couldn't find the solution by my own, please ;)


PierB

Pier B.

unread,
May 17, 2017, 11:54:46 AM5/17/17
to Salt-users
So, as usual I did found the solution right after my post, writing is usually my best way of understanding what's going wrong... Strangely in this case nothing was wrong ! I just did not test it the right way (was not sending any pillar data when testing .....).

Still I have a last issue, some of my app server needs a custom location to be defined in the proxy config file, I first thought of defining this custom_URL inside a grain on the app server but how could I retrieve this value from within the state from which I am updating the proxy config (role.proxy.add_client_proxy) ?

Any thoughts are more than welcome... Still searching by the time :)


Pier B

Pier B.

unread,
May 17, 2017, 2:39:57 PM5/17/17
to Salt-users
Again : I ended up using salt mine, mi first step in this, I have hard time getting custom grains using the mine, is there any special way of achieving this ?
my custom grains are defined in /etc/salt/grains.

here is my tries :
root@salt [~]: salt 'acd*' mine.get '*' network.ip_addrs
acdxxxxxxxxxx:
   
----------
    acdxxxxxxxxxx
:
       
- 192.168.xxx.xxx
 but :
root@salt [~]: salt 'acd*' mine.get '*' grains.item
acdxxxxxxxxxx:
   
----------

Anyone knows how to do this ?

Thanks

Pier B.

unread,
May 20, 2017, 3:46:36 PM5/20/17
to Salt-users
For the sake of humanism ;), I did solve my issue by updating mine data, following these advices :
https://github.com/saltstack/salt/issues/11501

launching a pillar.refresh followed by a mine.update did the trick. I still have to figure out how I can use these 2 functions in my orch state and I'll be done for now....

root@salt [~]: salt "*" mine.update
root@salt
[~]: salt "*" saltutil.refresh_pillar



Pier B.

unread,
May 20, 2017, 4:44:46 PM5/20/17
to Salt-users
Like this :
# MUST refresh pillar (saltmine functions are defined in pilars) + mine.update to get the latest data from newly created minion
#
saltutil
.refresh_pillar:
  salt
.function:
   
- tgt: '*'

# MUST update mine data to get the latest data from newly created minion
orchestrate_update_mine
:
  salt
.function:
   
- name: mine.update
   
- tgt: '*'

Reply all
Reply to author
Forward
0 new messages