salt icon indicating copy to clipboard operation
salt copied to clipboard

highstate doesn't work with multiple environment

Open BalintSzigeti opened this issue 10 years ago • 21 comments

my top.sls contains 'base' and 'live'. The base section is the first one. When I run the 'salt-call state.highstate' only 'base' section will be set. The 'salt-call state.highstate saltenv=live' returns with:

[INFO    ] Loading fresh modules for state activity
[ERROR   ] Template was specified incorrectly: False
[ERROR   ] No contents found in top file
local:
----------
          ID: states
    Function: no.None
      Result: False
     Comment: No Top file or external nodes data matches found.
     Started:
    Duration:
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   0.000 ms

I use salt-2015.8.3-1.el6.noarch

my top.sls looks:

base:
  '*':
    - yum
    - openssh.server
    - openssh.client
    - users
    - sudo
    - bash
live:
  '*':
    - salt.minion
    - network.{{ grains['fqdn'] }}
    - ntp
    - logrotate
    - iptables
    - rsyslog
......

BalintSzigeti avatar Jan 19 '16 09:01 BalintSzigeti

@BalintSzigeti, thanks for the report. I am wondering if your problem/an additional problem is the Template was specified incorrectly: False log statement. Is it possible for you to provide the debug log output? what happens if you remove the - network.{{ grains['fqdn'] }} line in your top file?

jfindlay avatar Jan 19 '16 17:01 jfindlay

hello

I removed the {{ grains['fqdn'] }} section but the issue is still exist.

BalintSzigeti avatar Jan 21 '16 15:01 BalintSzigeti

@BalintSzigeti, Thanks for the extra info. What is the debug log output in that case? What are your master and minion configs?

jfindlay avatar Jan 21 '16 22:01 jfindlay

output from debug log:

~]# salt-call state.highstate saltenv=live -l debug
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/_schedule.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/_schedule.conf
[DEBUG   ] Including configuration from '/etc/salt/minion.d/grains.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/grains.conf
[DEBUG   ] Using cached minion ID from /etc/salt/minion_id: infr01c
[DEBUG   ] Configuration file path: /etc/salt/minion
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Reading configuration from /etc/salt/minion
[DEBUG   ] Including configuration from '/etc/salt/minion.d/_schedule.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/_schedule.conf
[DEBUG   ] Including configuration from '/etc/salt/minion.d/grains.conf'
[DEBUG   ] Reading configuration from /etc/salt/minion.d/grains.conf
[DEBUG   ] Please install 'virt-what' to improve results of the 'virtual' grain.
[DEBUG   ] Initializing new SAuth for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506')
[DEBUG   ] Generated random reconnect delay between '1000ms' and '11000ms' (9055)
[DEBUG   ] Setting zmq_reconnect_ivl to '9055ms'
[DEBUG   ] Setting zmq_reconnect_ivl_max to '11000ms'
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506', 'aes')
[DEBUG   ] Initializing new SAuth for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506')
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506', 'clear')
[DEBUG   ] Decrypting the current master AES key
[DEBUG   ] Loaded minion key: /etc/salt/pki/minion/minion.pem
[DEBUG   ] Loaded minion key: /etc/salt/pki/minion/minion.pem
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] LazyLoaded state.highstate
[DEBUG   ] LazyLoaded grains.get
[DEBUG   ] LazyLoaded saltutil.is_running
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506', 'aes')
[DEBUG   ] Initializing new SAuth for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506')
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506', 'aes')
[DEBUG   ] Initializing new SAuth for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506')
[DEBUG   ] Loaded minion key: /etc/salt/pki/minion/minion.pem
[INFO    ] Loading fresh modules for state activity
[DEBUG   ] LazyLoaded jinja.render
[DEBUG   ] LazyLoaded yaml.render
[DEBUG   ] Could not find file from saltenv 'live', u'salt://top.sls'
[DEBUG   ] compile template: False
[ERROR   ] Template was specified incorrectly: False
[ERROR   ] No contents found in top file
[DEBUG   ] Loaded minion key: /etc/salt/pki/minion/minion.pem
[DEBUG   ] LazyLoaded config.option
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506', 'aes')
[DEBUG   ] Initializing new SAuth for ('/etc/salt/pki/minion', 'infr01c', 'tcp://1.1.1.1:4506')
[DEBUG   ] LazyLoaded highstate.output
local:
----------
          ID: states
    Function: no.None
      Result: False
     Comment: No Top file or external nodes data matches found.
     Started:
    Duration:
     Changes:

Summary for local
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   0.000 ms

minion conf:

 cat /etc/salt/minion|grep -vE '^#'
default_include: minion.d/*.conf
master: salt
ipv6: False
retry_dns: 30
master_port: 4506
user: root
pidfile: /var/run/salt-minion.pid
root_dir: /
pki_dir: /etc/salt/pki/minion

master.conf

interface: 1.1.1.1
ipv6: False
publish_port: 4505
timeout: 10
file_roots:
   base:
     - /srv/salt/base
   live:
     - /srv/salt/live
pillar_roots:
   base:
     - /srv/pillar/base
order_masters: false
syndic_master: 1.3.1.2
syndic_master_port: 4506
syndic_pidfile: /var/run/salt-syndic.pid
syndic_log_file: /var/log/salt/syndic
log_file: /var/log/salt/master
key_logfile: /var/log/salt/key
log_level_logfile: debug
log_datefmt_logfile: '%Y-%m-%d %H:%M:%S'

I think the saltenv attribute is not working. If I remove it from the command the highstate is executed but ONLY the first (base) section.

BalintSzigeti avatar Jan 22 '16 15:01 BalintSzigeti

@BalintSzigeti, is your top.sls located in your base environment and/or your live environment?

jfindlay avatar Jan 22 '16 21:01 jfindlay

This also may be useful: https://docs.saltstack.com/en/latest/ref/states/top.html#how-top-files-are-compiled.

jfindlay avatar Jan 22 '16 21:01 jfindlay

I'm having this same issue. I believe it's because my base: is not in the default location.

hartloosli avatar Jan 23 '16 06:01 hartloosli

Here's my /etc/salt/master;

22:05:01 jim@NSA-LAPTOP-84 salt $ > cat ../etc/master
# If it's not in this file, just assume that the salt master is running the default options

# Attempting to force all environments to use the top.sls in the base environment.

top_file_merging_strategy: same
default_top: /srv/salt/states/top.sls

# These file and roots will allow us to separate out environments
file_roots:
  base:
    - /srv/salt/states
  infra:
    - /srv/salt/infra/states
  production:
    - /srv/salt/prod/states
  staging:
    - /srv/salt/stage/states
  development:
    - /srv/salt/dev/states

pillar_roots:
  base:
    - /srv/salt/pillars
  infra:
    - /srv/salt/infra/pillars
  production:
    - /srv/salt/prod/pillars
  staging:
    - /srv/salt/stage/pillars
  development:
    - /srv/salt/dev/pillars

hartloosli avatar Jan 23 '16 06:01 hartloosli

I have the saltstack 'official' redis formula in my dev environment, and it should be getting applied.

[root@ip-aws salt]# salt 'redis*' state.highstate -l debug
[DEBUG   ] Reading configuration from /etc/salt/master
[DEBUG   ] Missing configuration file: /root/.saltrc
[DEBUG   ] Configuration file path: /etc/salt/master
[WARNING ] Insecure logging configuration detected! Sensitive data may be logged.
[DEBUG   ] Reading configuration from /etc/salt/master
[DEBUG   ] Missing configuration file: /root/.saltrc
[DEBUG   ] MasterEvent PUB socket URI: ipc:///var/run/salt/master/master_event_pub.ipc
[DEBUG   ] MasterEvent PULL socket URI: ipc:///var/run/salt/master/master_event_pull.ipc
[DEBUG   ] Initializing new AsyncZeroMQReqChannel for ('/etc/salt/pki/master', 'ip-aws-ip.us-west-2.compute.internal_master', 'tcp://127.0.0.1:4506', 'clear')
[DEBUG   ] LazyLoaded local_cache.get_load
[DEBUG   ] get_iter_returns for jid 20160123061659875921 sent to set(['redis.dev.somedomain.io']) will timeout at 06:17:04.880252
[DEBUG   ] jid 20160123061659875921 return from redis.dev.somedomain.io
[DEBUG   ] LazyLoaded highstate.output
redis.dev.somedomain.io:
----------
          ID: states
    Function: no.None
      Result: False
     Comment: No Top file or external nodes data matches found.
     Started:
    Duration:
     Changes:

Summary for redis.dev.somedomain.io
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
Total run time:   0.000 ms
[DEBUG   ] jid 20160123061659875921 found all minions set(['redis.dev.somedomain.io'])
ERROR: Minions returned with non-zero exit code

hartloosli avatar Jan 23 '16 06:01 hartloosli

Here's the top.sls found at /srv/salt/states/top.sls:

base:
  # Things in global need to be super super non-volatile. I'm including it for the edge case that some utility needs to be everywhere, and needs to be there quickly.
  '*': global

infra:
# There is one true jenkins server. It lives in the infra subnet/vpc and can access anything. If you are making manual config changes to Jenkins, you're probably in the wrong.
  'role:jenkins':
    - match: grain
    - jenkins
    - nginx
    - jenkins.nginx

# Production is in 10.10/16
prod:
  'role:frontend':
    - match: grain
    - frontend
  'role:api':
    - match: grain
    - api
  'role:mongodb':
    - match: grain
    - mongodb
  'role:redis':
    - match: grain
    - redis

# Staging is in 10.20/16
stage:
  'role:frontend':
    - match: grain
    - frontend
  'role:api':
    - match: grain
    - api
  'role:mongodb':
    - match: grain
    - mongodb
  'role:redis':
    - match: grain
    - redis

# Development is in 10.30/16
dev:
  'role:frontend':
    - match: grain
    - frontend
  'role:api':
    - match: grain
    - api
  'role:mongodb':
    - match: grain
    - mongodb
  'role:redis':
    - match: grain
    - redis
    - redis.server

If anyone has some insight, I would be very appreciative.

hartloosli avatar Jan 23 '16 06:01 hartloosli

in my base env.

On 22/01/2016 21:30, Justin Findlay wrote:

@BalintSzigeti https://github.com/BalintSzigeti, is your top.sls located in your base environment and/or your live environment?

— Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/30434#issuecomment-174054924.

BalintSzigeti avatar Jan 23 '16 17:01 BalintSzigeti

I'm also having a similar issue with multiple environments not working. I've tried about every combination of directory tree structure, with and without a top.sls in each environment. It seems as though each environment is requiring a top.sls file in it regardless of the settings in the master config file. It is my understanding from reading the docs and reading the comments in the master config file that I should be able to have a single top.sls file in the base environment that references and defines all other environments. Is that true or have I misunderstood the documentation?

I currently have the following set in my master.conf.

file_roots:
  base:
    - /srv/salt/states/base
  dev:
    - /srv/salt/states/dev

top_file_merging_strategy: same

default_top: base

This means that all I should require is a top.sls file in /srv/salt/states/base and that file should be able to be used and referenced by all environments. Correct?

Here is an example of my top.sls in the base environment

base:
  '*':
    - salt-minion
    - common.packages
    - common.users
    - env
dev:
  '*':
    - packages

Finally, here are the package versions I have installed.

salt.noarch                             2015.8.3-1.el7                 @saltstack-repo
salt-api.noarch                         2015.8.3-1.el7                 @saltstack-repo
salt-cloud.noarch                       2015.8.3-1.el7                 @saltstack-repo
salt-master.noarch                      2015.8.3-1.el7                 @saltstack-repo
salt-minion.noarch                      2015.8.3-1.el7                 @saltstack-repo
salt-ssh.noarch                         2015.8.3-1.el7                 @saltstack-repo

Please let me know if you need me to test anything out. I'm willing to help out however I can. I'm trying to replace an aging puppet environment and I really want Saltstack to be that replacement. :)

dmabry avatar Jan 23 '16 20:01 dmabry

@hartloosli, @dmabry, the simpler thing to do is to have a single top file in one environment, but multiple top files should also work.

jfindlay avatar Jan 25 '16 20:01 jfindlay

I've got the same problem in 2015.8.5, which up to now I thought was a (git_)pillar problem. But since @BalintSzigeti doesn't seem to use Git at all, the problem might really be something else. However, here's my test setup: Two Git repos, one for the top.sls file (salt_top.git) and the other one for the actual data (salt.git). Both repos have a pillar and a states directory, and salt.git also has a development branch. In salt_top.git, there are pillar/top.sls and states/top.sls with the following content each (not sure if pillar and states could share one top.sls file, though):

base:
  '(minion1|minion2).example.de':
    - match: pcre
    - test

development:
  'minion3.example.de':
    - test

In salt.git, there are the following files:

  • states/test/init.sls:

    {% set content = salt['pillar.get']('test_content') %}
    
    test_file:
    file.managed:
      - name: /tmp/testfile
      - contents: {{ content }}
    
  • pillar/test/init.sls:

    • Branch master: test_content: foo
    • Branch development: test_content: bar

/etc/salt/master.d/local.conf looks like this:

fileserver_backend:
  - git

gitfs_provider: gitpython
gitfs_root: states

gitfs_remotes:
  - git-salt:salt_top.git
  - git-salt:salt.git

top_file_merging_strategy: same

git_pillar_provider: gitpython
git_pillar_root: pillar

ext_pillar:
  - git:
    - git-salt:salt_top.git:
      - name: top
  - git:
    - master git-salt:salt.git:
      - name: base
      - env: base
  - git:
    - development git-salt:salt.git:
      - name: development
      - env: development

ext_pillar_first: True

Now, when I run highstate for minion3, I get the following:

# salt 'minion3.example.de' state.highstate
minion3.example.de:
----------
          ID: states
    Function: no.None
      Result: False
     Comment: No Top file or external nodes data matches found.
     Started: 
    Duration: 
     Changes:   

Summary for minion3.example.de
------------
Succeeded: 0
Failed:    1
------------
Total states run:     1
ERROR: Minions returned with non-zero exit code

heini avatar Feb 07 '16 08:02 heini

Saltstack documentation are written by saltstack developer, and most saltstack lecturer just overlook saltstack different than typical Linux/ux sysops config structure, which usually locate under SINGLE folder or use symbolic link as a hint, if they want to do so (e.g. nginx) .

However, this is not in saltstack case. In fact, Salt "configuration" may actually split into 4 part (and all this info is scattered around).

  1. (Mandatory, salt master server) Salt master daemon config location /etc/salt/master
  2. (Mandatory, salt master server) The important devops structure( states, sls files) part are set DEFAULT to /srv/salt
  3. (Mandatory [if use master-minion setup], salt minion server) Salt minion dameon config location /etc/salt/minion
  4. (Optional, salt minion server) Salt minion grains or masterless salt devops(states, sls files) set DEFAULT to /srv/salt

The configuration location (-c ) of salt /salt-call command are refer to DAEMON config location, NOT the devops parts.

If you want to specify your own saltstack devops setup file( states, sls files) location, you need to edit /etc/salt/master or /etc/salt/minion , uncomment file_roots and put your own path.

P/S: Yes, this is a simple "did you place the file in the correct location" issue. Yes, the information is all inside https://docs.saltstack.com/en/latest/ref/states/top.html#how-top-files-are-compiled It seems the writer having trouble to make it simple for sysops.

commutecat avatar Feb 29 '16 17:02 commutecat

Think the "Needs Testcase" label can be removed since I provided one in my previous comment.

heini avatar Mar 12 '16 09:03 heini

@heini, the Needs Testcase label means that there should be a test written for this as part of the automated testing of salt, https://docs.saltstack.com/en/latest/topics/development/labels.html#other.

jfindlay avatar Mar 14 '16 21:03 jfindlay

I just encountered the same issue, receiving the error "No Top file or external nodes data matches found." I am using gitfs.

I found that if I specify the master option top_file_merging_strategy with any value, my top file is not visible to the minions and I get the error. If I comment it out (shipped default) then I get a top file and things work.

of important note, Once I performed a successful highstate on my minions only top_file_merging_strategy: merged displays the problem. Specifying 'same' no longer has the issue. Specifying 'same' was an issue previously, I started out with that value which lead me down this road, and I tested it a few times before doing the successful highstate.

My working master.d/localconfig.conf:

# local config for the salt-master

# random options
hash_type: sha256

# file_ignore_regex:
#  - '/\.svn($|/)'
#  - '/\.git($|/)'

# file backend
fileserver_backend:
 - git
 - roots

# set file roots
file_roots:
  local_base:
    - /srv/salt/env/base/states
    - /srv/salt/env/base/files
    - /srv/salt/env/base/formulae

# top options
# top_file_merging_strategy: merged

# set gitfs options
gitfs_pubkey: /etc/salt/pki/git/gitlab_rsa.pub
gitfs_privkey: /etc/salt/pki/git/gitlab_rsa
gitfs_provider: pygit2

# set gitfs roots
gitfs_remotes:
 - [email protected]:salt/states.git
 - [email protected]:salt/formulae.git

# set pillar root
pillar_roots:
  local_base:
    - /srv/pillar/env/base/pillar

# set pillar gitfs
git_pillar_pubkey: /etc/salt/pki/git/gitlab_rsa.pub
git_pillar_privkey: /etc/salt/pki/git/gitlab_rsa
ext_pillar:
  - git:
    - master [email protected]:salt/pillar.git

working (implicit top_file_merging_strategy)

05:23:54 [root@saltmaster master.d]# salt 'saltmaster.domain.org' state.show_top
saltmaster.funklabs.org:
    ----------
    base:
        - baseline.environment.prompts
        - baseline.packages
        - salt.minion
        - salt.minion.config
        - salt.master

failing (explicit top_file_merging_strategy)

05:23:01 [root@saltmaster master.d]# salt 'saltmaster.funklabs.org' state.show_top
saltmaster.funklabs.org:
    ----------

My versions

05:31:28 [root@saltmaster master.d]# salt --versions
Salt Version:
           Salt: 2015.8.8.2

Dependency Versions:
         Jinja2: 2.7.2
       M2Crypto: Not Installed
           Mako: Not Installed
         PyYAML: 3.11
          PyZMQ: 14.7.0
         Python: 2.7.5 (default, Nov 20 2015, 02:00:19)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.5
           cffi: 0.8.6
       cherrypy: 3.2.2
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
        libgit2: 0.21.0
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: 0.21.4
   python-gnupg: Not Installed
          smmap: Not Installed
        timelib: Not Installed

System Versions:
           dist: centos 7.2.1511 Core
        machine: x86_64
        release: 3.10.0-327.el7.x86_64
         system: CentOS Linux 7.2.1511 Core

funkknight avatar Apr 06 '16 05:04 funkknight

I'm seeing this as well. I've done a fair bit of logging on this and trying various configuration options regarding top_file_merging_strategy in master and/or slave and have arrived at no combination in which a minion will see its top file correctly when using GitFS with multiple environments. I haven't yet tested with just one environment but I'll get to that at some point -- right now I'm just using state.apply mystate.substate pillar='{...}' in a bash loop to my states for this proof of concept while I try to figure out which combination of gitfs and environments are viable.

In any case, when I get some time away from the deployment I have a due date on I'll gather up, redact, and post my logs for the variations I've tested on.

Thanks, -Andrea

iacapps-arutledge avatar Jul 01 '16 18:07 iacapps-arutledge

Just gave it another try with 2016.11.0rc2. Works for me, now.

heini avatar Nov 11 '16 20:11 heini