saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Get access to the Salt software package repository here:
https://repo.saltproject.io/
Apache License 2.0
14.16k stars 5.48k forks source link

host.only writes unicode names under python2.7 with pillar provided on command line #53880

Closed wilful closed 7 months ago

wilful commented 5 years ago

Description of Issue

Hi all!

I try to pass Pillar through the command line, but it’s not quite what I’m expecting. For example, my config for the Hosts file:

{% for host in pillar.borg.lookup.monitor.hosts  %}
{{ host.ip }}:
  host.only:
    - hostnames: {{ host.names }}
{% endfor %}

Example pillar:

salt my_host pillar.item borg:lookup:monitor
my_host:
    ----------
    borg:lookup:monitor:
        ----------
        hosts:
            |_
              ----------
              ip:
                  X.X.X.X
              names:
                  - name1
                  - name2

This works fine until I want to change the data in the command line:

salt my_host state.apply borg.hosts saltenv=development pillar='{"borg":{"lookup":{"monitor":{"hosts":[{"ip":"Y.Y.Y.Y","names":["name1","name2"]}]}}}}'

In my case, I get data:

cat /etc/hosts
Y.Y.Y.Y               u'name1' u'name2'

How can I use parameters in the command line without escaping?

Setup

# cat hosts.sls 
{% for host in pillar.borg.lookup.monitor.hosts  %}
{{ host.ip }}:
  host.only:
    - hostnames: {{ host.names }}
{% endfor %}
borg:
    lookup:
        monitor:
          hosts:
            - ip: X.X.X.X
              names:
                - name1
                - name2

Steps to Reproduce Issue

Versions Report

Salt Version:
           Salt: 2019.2.0

Dependency Versions:
           cffi: Not Installed
       cherrypy: unknown
       dateutil: Not Installed
      docker-py: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.5.6
   mysql-python: 1.2.5
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: 3.7.0
         pygit2: Not Installed
         Python: 2.7.5 (default, Oct 30 2018, 23:45:53)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.3.0
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: centos 7.6.1810 Core
         locale: UTF-8
        machine: x86_64
        release: 3.10.0-957.10.1.el7.x86_64
         system: Linux
        version: CentOS Linux 7.6.1810 Core
waynew commented 5 years ago

Thanks for the report!

Not sure exactly what the issue is here, but I could definitely reproduce with the provided info, only under Python2, of course.

The problem is happening somewhere in salt/modules/hosts.py(def get_alias and def set_host) and salt/states/host.py (def only).

We should probably just have a function that compares aliases so that can be properly tested on its own.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] commented 4 years ago

Thank you for updating this issue. It is no longer marked as stale.

twangboy commented 7 months ago

Closing as Python 2 is no longer supported.