Salt 状态文件无法从 Pillar 加载信息

Salt 状态文件无法从 Pillar 加载信息

当我尝试将我的状态文件应用到我的 minion 时出现此错误:client.school.test:数据无法编译:

Rendering SLS 'base:nextcloud2' failed: Jinja variable 'list object' has no attribute 'db_name'

我正在尝试输入创建 mysql 数据库和用户所需的数据。数据是目录 /srv/pillar 中的文件 mysql.sls

  mysql:
  - user: dbuser
  - password: Password91!
  - db_name: nextcloud

该目录还包含所需的 top.sls 文件:

base:
  'G@os:Rocky':
  - mysql

在目录 /srv/salt 中,我有一个状态文件,我正尝试将支柱数据插入到其中:

{% set config = pillar.get("mysql", {}) %}

install_network_packages:
  pkg.installed:
    - pkgs:
      - httpd
      - redis
      - wget
  archive:
      - extracted
      - name: /var/www/html/
      - source: https://download.nextcloud.com/server/releases/nextcloud-22.2.0.tar.bz2
      - skip_verify: true
      - if_missing: /var/www/html/nextcloud

copyconf:
 file.managed:
 - name: /etc/httpd/conf.d/nextcloud.conf
 - source: salt://nextcloud.conf
 - mode: 777

redis:
  pkg.installed: []
  service.running:
    - enable: True
    - require:
      - pkg: redis

firewall:
  cmd.run:
  - name: |
      firewall-cmd --add-service=http --permanent
      firewall-cmd --reload
      dnf -y module switch-to php:7.4
      dnf install -y php-7.4.* php-gd-7.4.* php-mbstring-7.4.* php-intl-7.4.* php-pecl-apcu php-mysqlnd-7.4.* php-opcache-7.4.* php-json-7.4.* php-pecl-zip
      mkdir /var/www/html/nextcloud/data
      dnf install -y mariadb mariadb-server python3-PyMySQL
      systemctl enable mariadb.service
      systemctl start mariadb.service

/var/www/html/:
  file.directory:
    - user: apache
    - group: apache
    - recurse:
      - user
      - group

httpd:
  pkg.installed: []
  service.running:
    - enable: True
    - require:
      - pkg: httpd

mysql:
  mysql_database.present:
    - name: {{ config["db_name"] }}
  mysql_user.present:
    - name: {{ config["user"] }}
    - host: localhost
    - password: {{ config["password"] }}
  mysql_grants.present:
    - grant: all privileges
    - database: nextcloud.*
    - user: {{ config["user"] }}
    - host: localhost

我重启了 salt master 服务,尝试在 Google 上搜索可能的解决方案,但无济于事。希望有人能帮我解决这个问题!

答案1

从表面上看,你的代码中的缩进top.sls不对。该- mysql部分需要再缩进两个空格,如下所示:

base:
  'G@os:Rocky':
    - mysql

相关内容