首页 > 解决方案 > 失败:Jinja 变量“salt.utils.context.NamespacedDictWrapper 对象”没有属性“env”

问题描述

刚刚继承了一个盐实现,我遇到了一个我似乎无法弄清楚的错误。我有 5 个运行完美的仆从,但是当我添加第 6 个时,我收到以下错误:

Rendering SLS 'production:clientxyz.init' failed: Jinja variable 'salt.utils.context.NamespacedDictWrapper object' has no attribute 'env'

这看起来是特定于第 6 个仆从,因为所有其他仆从都成功运行。我可以对 minion 执行 test.ping,因此通信似乎正常。

以下是有关当前部署的一些详细信息:

盐奴才

           Salt: 3000.3

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.6.2
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Apr 15 2020, 17:07:12)
   python-gnupg: 0.3.8
         PyYAML: 3.11
          PyZMQ: 15.2.0
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-1109-aws
         system: Linux
        version: Ubuntu 16.04 xenial

盐师傅

Salt Version:
           Salt: 3000.2

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.6.1
      docker-py: Not Installed
          gitdb: 2.0.3
      gitpython: 2.1.8
         Jinja2: 2.10
        libgit2: 0.26.0
       M2Crypto: Not Installed
           Mako: 1.0.7
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: 0.26.2
         Python: 2.7.17 (default, Apr 15 2020, 17:20:14)
   python-gnupg: 0.4.1
         PyYAML: 3.12
          PyZMQ: 16.0.2
          smmap: 2.0.3
        timelib: Not Installed
        Tornado: 4.5.3
            ZMQ: 4.2.5

System Versions:
           dist: Ubuntu 18.04 bionic
         locale: UTF-8
        machine: x86_64
        release: 5.3.0-1023-aws
         system: Linux
        version: Ubuntu 18.04 bionic

客户端xyz.init

clientxyz_group:
  group.present:
    - name: clientxyz
    - system: True

clientxyz_user:
  user.present:
    - name: clientxyz
    - groups:
      - clientxyz
  require:
    - group: clientxyz_group

{% if pillar['env'] == 'prod' %}
/opt/prod/clientxyz/.env_file.prod:
  file:
    - managed
    - template: jinja
    - source: salt://env_templates/production/files/.env_file.prod
 {% endif %}

顶部.sls

  '*':
    - 数据
    - 文件哈希
    - global_vars
  
# 生产
  '客户XYZ:
    - 客户xyz
    - 生产共享
  “客户ABC”:
    - 客户abc
    - 生产共享

客户端xyz.sls

#!yaml|gpg
fb_files:
  /var/log/syslog: 客户端xyz
环境:产品
命名空间:生产
订阅:

DB_HOST: <数据库主机名>
DB_PORT:5432
DB_USER:clientxyz_user
DB_NAME:clientxyz_database
DB_PWD: |
  -----开始PGP消息-----

  已删除加密密码
  -----结束 PGP 消息-----

我不知道这里面还包括什么,idk,如果这是master和minion之间的版本问题,或者那个'env'错误是指clientxyz.init中的piller ['env']引用。有点不知所措,任何帮助将不胜感激!

标签: jinja2salt-stack

解决方案


事实证明这是 gitlab 和部署密钥的问题。Minion 正在运行 repo 的缓存版本,并且没有使用最新的支柱进行更新。


推荐阅读