Salt+Json Renderer issue

98 views
Skip to first unread message

Akilesh K

unread,
May 28, 2014, 2:27:09 AM5/28/14
to salt-...@googlegroups.com
Hi,
I get the error saying 'Multiple dictionaries defined in argument of state '.

I am sure that the sate file itself is not wrong as the same file in yaml format is compiled and loaded properly but when I convert to json I get the above error.

The origin of the error message is from '/usr/lib/python2.7/dist-packages/salt/state.py' from inside State.verify_high() method.

Inside the method there is a check to ensure 'Make sure that there is only one key in the dict'. I am not sure if this is necessary and also why this check does not run when I use yaml renderer. Can any one help me out?

Below I have pasted the sls file itself.
#!json
{
    "mysql-server": {
        "pkg": [
            "installed"
        ],
        "service": [
            "running",
            {
                "name": "mysql",
                "watch": [
                    {
                        "pkg": "mysql-server"
                    },
                    {
                        "ini": "mysql-conf-file"
                    }
                ]
            }
        ]
    },
    "mysql-conf-file": {
        "file": [
            "managed",
            {
                "name": "/etc/mysql/my.cnf",
                "user": "root",
                "group": "root",
                "mode": "644",
                "require": [
                    {
                        "pkg": "mysql-server"
                    }
                ]
            }
        ],
        "ini": [
            "options_present",
            {
                "name": "/etc/mysql/my.cnf",
                "sections": {
                    "mysqld": {
                        "bind-address": "0.0.0.0",
                        "collation-server": "utf8_general_ci",
                        "init-connect": "'SET NAMES utf8'",
                        "character-set-server": "utf8"
                    }
                },
                "require": [
                    {
                        "file": "mysql-conf-file"
                    }
                ]
            }
        ]
    }
}

Dmitry Malinovsky

unread,
May 28, 2014, 4:53:40 AM5/28/14
to salt-...@googlegroups.com
This is because your state is malformed.

In [1]: import json

In [2]: sls = '''
mysql-server:
  pkg:
    - installed
  service:
    - running
    - name: mysql
    - watch:
      - pkg: mysql-server
      - ini: mysql-conf-file
'''

In [3]: from yaml import load

In [4]: o = load(sls)

In [9]: print(json.dumps(o, indent=1))
{
 "mysql-server": {

  "service": [
   "running",
   {
    "name": "mysql"
   },
   {
    "watch": [
     {
      "pkg": "mysql-server"
     },
     {
      "ini": "mysql-conf-file"
     }
    ]
   }
  ],
  "pkg": [
   "installed"
  ]
 }
}

Akilesh K

unread,
May 28, 2014, 6:02:52 AM5/28/14
to salt-...@googlegroups.com
So should each argument to the state function be given in a separate dict with one key? Isn't this inefficient? Isn't passing a single dict packed with keyword argument better?

Dmitry Malinovsky

unread,
May 28, 2014, 6:37:26 AM5/28/14
to salt-...@googlegroups.com
It is, but you should think of it as salt state file syntax requirement.

Akilesh K

unread,
May 28, 2014, 9:13:50 AM5/28/14
to salt-...@googlegroups.com
I agree. But I am going to bring the original issue back. Below is another sls from another state file. As you can see this one has one single dict and seems to work perfectly fine. There seems to be a certain case where the check seems to happen and fail, not always.

Please help me find the cause as I have a bunch of state configured this way and only a few of them fail. You can see this project 'https://github.com/CSSCorp/openstack-automation' in case you want to see my sls.

    "nova-conf": {
        "file": [
            "managed",
            {
                "name": "/etc/nova/nova.conf",
                "user": "nova",
                "password": "nova",
                "mode": "644",
                "require": [
                    {
                        "pkg": "nova-compute"
                    }
                ]
            }
        ]
   }


--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Dmitry Malinovsky

unread,
May 28, 2014, 11:55:35 PM5/28/14
to salt-...@googlegroups.com
The easiest way is to ALWAYS write a correct state file so salt can properly render it. If you can find some edge cases when you can write a state file differently than expected, you should open an issue on github.

If you want to go deeper, you can look through the source code to understand why it is rendered correctly, but it's huge and complex. So I'd suggest to play by the salt rules, not yours.
Reply all
Reply to author
Forward
0 new messages