Score:0

Salt state file doesn't load info from pillar

no flag

I'm getting this error when I'm trying to apply my statefile to my minion: client.school.test: Data failed to compile:

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

I'm trying to enter the data required to create a mysql database and user. The data is the file mysql.sls in the directory /srv/pillar

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

That directory also has the required top.sls file:

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

In the directory /srv/salt i have the state file i'm trying to insert the pillar data into:

{% 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

I restarted the salt master service, tried to google possible solutions but to no avail. Hope someone can help me fix this!

Score:0
mx flag

From the looks of it the indentation in your top.sls is off. The - mysql part needs to be indented with two more spaces like this:

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

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.