Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

such as ansible groups['etcd']

{% for h in groups['etcd'] %}{{ hostvars[h]['NODE_NAME'] }}=http://{{ hostvars[h]['url_host'] }}:2379{% if not loop.last %},{% endif %}{% endfor %}

expect some jinja:

{% set item_list = [] %}
{% for h in nodegroups['etcd'] %}
 {% do item_list.append("etcd{}=http://{}".format(loop.index, h))%}
{% endfor %}
{{ ','.join(item_list) }}
You must be logged in to vote
root@salt00:/srv/pillar/mine# salt-call mine.valid
local:
    ----------
    test.ping:
oot@salt00:/srv/pillar/mine# cat init.sls
mine_functions:
  test.ping: []

root@salt00:/srv/pillar/mine# cd ..
root@salt00:/srv/pillar# cat top.sls
base:
  '*':
    - mine

Replies: 1 comment · 3 replies

Comment options

there is a way but it is very round about because this is not functionality that is normally useful in salt. nodegroups are considered a targeting method not an information system.

that being said .. what you can do is setup a mine_function on all minions for test.ping this will be true on all systems and will be stored on the master. this will allow minions to get the targeting info from any minions that exist. with something like the following.

{% set nodes = salt["mine.get"]('<nodegroup name>', "test.ping", tgt_type="nodegroup").keys() | list %}

the .keys() | list is to ignore the return from the mine_function and just return the list of minions that matched the target info.

you can read more about the salt mine here https://docs.saltproject.io/en/latest/topics/mine/

You must be logged in to vote
3 replies
@zhangguanzhang
Comment options

does't work

name: "etcd-cluster" # {% set nodes = salt["mine.get"]('etcd', "test.ping", tgt_type="nodegroup").keys() | list %}{{ nodes }}

run:

$ salt -N etcd state.apply deploy.midware.etcd.install
....
              diff:
                  --- 
                  +++ 
                  @@ -1,4 +1,4 @@
                  -name: "etcd-cluster"
                  +name: "etcd-cluster" # []
                   services:
$ salt-run config.get nodegroups 
etcd:
    L@10.2x.xx.xxx
@whytewolf
Comment options

did you setup the mine like i had actually said in the first place? mine.get isn't going to do anything if the mine_function isn't setup.

root@salt00:/srv/pillar/mine# salt-call slsutil.renderer salt://tests/fetch.sls default_renderer=jinja
local:

    ['home', 'salt00', 'media']
root@salt00:/srv/pillar/mine# cat /srv/salt/tests/fetch.sls
{% set nodes = salt["mine.get"]("all","test.ping", tgt_type="nodegroup").keys()|list %}
{{nodes}}
@whytewolf
Comment options

root@salt00:/srv/pillar/mine# salt-call mine.valid
local:
    ----------
    test.ping:
oot@salt00:/srv/pillar/mine# cat init.sls
mine_functions:
  test.ping: []

root@salt00:/srv/pillar/mine# cd ..
root@salt00:/srv/pillar# cat top.sls
base:
  '*':
    - mine
Answer selected by zhangguanzhang
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.