Using salt['cp.list_master']() in state only returns empty []

415 views
Skip to first unread message

whorain...@googlemail.com

unread,
May 25, 2014, 1:21:16 PM5/25/14
to salt-...@googlegroups.com
Hi Mailing List,

I would like to iterate through a list of files on my local server. That is because I have a tool that has about 15 config files that all need the same file settings, are templates and so on. I'm using "local" salt, so as in file_client: local, and also a changed file_roots as I have multiple file roots.

When I run cp.list_master on the command line, it works like a charm:
root@mail /srv/salt # salt-call cp.list_master saltenv=mailserver prefix=dovecot/templates
local:
    - dovecot/templates/users
    - dovecot/templates/dovecot.conf
 [...]



In a state:

foobar:          
  cmd.run:
    - name: echo {{ salt['cp.list_master']('saltenv=mailserver', 'prefix=dovecot/templates') }}


It gives me:

local:
----------
          ID: foobar
    Function: cmd.run
        Name: echo []
      Result: True
     Comment: Command "echo []" run
     Changes:  
              ----------
              pid:
                  3426
              retcode:
                  0
              stderr:
                 
              stdout:
                  []



I cant really find my error.. Do any of you have a hint?

Vitold S

unread,
May 26, 2014, 3:30:20 AM5/26/14
to salt-...@googlegroups.com
Hello,

1. When copy does not occure it may version mismatch.
2. Why you useing echo? Just use .coppy command to /tmp and after that use echo.

воскресенье, 25 мая 2014 г., 21:21:16 UTC+4 пользователь whorain...@googlemail.com написал:

whorain...@googlemail.com

unread,
May 26, 2014, 1:47:21 PM5/26/14
to salt-...@googlegroups.com
Hi Vitold,

1. I dont think it is a version missmatch as i'm using local salt (file_client: local).
2. This is only a way to see if it works out at all. My target is to work with the output of cp.list_master later. So the echo is just that you guys can copy paste and see if it works.

What would really interest me; does this work for anybody or is it a bug? I read some of the code today and to me it seems ok, anyhow, whatever I do, I do not get a result when using {{ salt['cp.list_master']('saltenv=mailserver', 'prefix=dovecot/templates') }} in any state file.

If anybody had the time to just test the function in a state file, that would be awesome :)

Colton Myers

unread,
May 28, 2014, 7:08:32 PM5/28/14
to salt-...@googlegroups.com
I'm betting that the `cp` function when used inside of a state on a masterless minion is still trying to query the master, not looking in the local fileclient.  In the debug output, it should show the results of the state file after jinja templating.  Does that result show the list of files after `echo`, or is it empty there, too?

--
Colton Myers


--
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.

whorain...@googlemail.com

unread,
May 31, 2014, 7:12:11 AM5/31/14
to salt-...@googlegroups.com
Basepi, in that case it also should not work on the command line. When i'm running salt-call cp.list_master saltenv=mailserver on the command line on a machine with local fileclient, I do get the correct results.

I tried this on a master server / minions setup and got the following results:

On the master:
user@machine:~# salt-call cp.list_master saltenv=mailserver
local:
    - README
    - config/config.sls

On the client:
user@machine:~# salt-call cp.list_master saltenv=mailserver
local:
    - README
    - config/config.sls


In a state file on the server:
/root/testfile:
  file.append:
    - text: |
        {{ salt['cp.list_master']('saltenv=mailserver') }}

Contents on the remote client:
root@smurfmail:~# cat testfile
[]




On Sunday, May 25, 2014 7:21:16 PM UTC+2, whorain...@googlemail.com wrote:

Colton Myers

unread,
Jun 9, 2014, 6:17:28 PM6/9/14
to salt-...@googlegroups.com
Right, theoretically it would not work in either place, but it's possible that the state system specifically is not checking for that masterless flag and so is trying to query directly.  It's definitely a bug either way.

Can you check the debug log on the minion for the templated output of the file just to make sure that the list of files is not properly being populated?  Just trying to pinpoint the point of failure.

--
Colton Myers


Reply all
Reply to author
Forward
0 new messages