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.17k stars 5.48k forks source link

cmd.run/cmd.script getting TypeError: coercing to Unicode: need string or buffer, bool found #12400

Closed feiming closed 10 years ago

feiming commented 10 years ago

I had tried with cmd.run and cmd.script. Both gave the same error as below.

This is the error message:

[root@experiment moosefs]# salt-call --local state.highstate -l debug
...
...
...
          ID: salt://moosefs/files/install_script.sh
    Function: cmd.script
      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.6/site-packages/salt/state.py", line 1371, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.6/site-packages/salt/states/cmd.py", line 749, in script
                  cmd_all = __salt__['cmd.script'](source, **cmd_kwargs)
                File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 995, in script
                  saltenv=saltenv)
                File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 261, in _run
                  if not os.path.isfile(shell) or not os.access(shell, os.X_OK):
                File "/usr/lib64/python2.6/genericpath.py", line 29, in isfile
                  st = os.stat(path)
              TypeError: coercing to Unicode: need string or buffer, bool found
     Changes:   

I'm running a masterless Salt. This is the state file and other related info:

[root@experiment moosefs]# cat master.sls 
{% from "moosefs/map.jinja" import moosefs with context %}

include:
  - moosefs

salt://moosefs/files/install_script.sh:
  cmd.script:
    - cwd: /tmp
    - user: root
    - shell: True
[root@experiment moosefs]# cat files/install_script.sh 
#!/bin/bash

cd /tmp
wget -c http://moosefs.org/tl_files/mfscode/mfs-1.6.27-5.tar.gz
tar xzvf mfs-1.6.27-5.tar.gz
cd mfs-1.6.27
./configure --prefix=/usr --sysconfdir=/etc/moosefs --localstatedir=/var/lib --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --disable-mfsmount
make
make install
[root@experiment moosefs]# salt-minion --version
salt-minion 2014.1.0
[root@experiment moosefs]# uname -a
Linux experiment 2.6.32-431.11.2.el6.x86_64 #1 SMP Tue Mar 25 19:59:55 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
feiming commented 10 years ago

cmd.run error message:

          ID: Install_Master
    Function: cmd.run
        Name: cd /tmp
wget -c http://moosefs.org/tl_files/mfscode/mfs-1.6.27-5.tar.gz -O mfs.tar.gz
tar -xzvf mfs.tar.gz
cd mfs-1.6.27
./configure --prefix=/usr --sysconfdir=/etc/moosefs --localstatedir=/var/lib --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --disable-mfsmount
make
make install

      Result: False
     Comment: An exception occurred in this state: Traceback (most recent call last):
                File "/usr/lib/python2.6/site-packages/salt/state.py", line 1371, in call
                  **cdata['kwargs'])
                File "/usr/lib/python2.6/site-packages/salt/states/cmd.py", line 589, in run
                  name, timeout=timeout, **cmd_kwargs
                File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 803, in run_all
                  saltenv=saltenv)
                File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 261, in _run
                  if not os.path.isfile(shell) or not os.access(shell, os.X_OK):
                File "/usr/lib64/python2.6/genericpath.py", line 29, in isfile
                  st = os.stat(path)
              TypeError: coercing to Unicode: need string or buffer, bool found
     Changes:   

state file:

include:
  - moosefs

Install_Master:
  cmd.run:
    - name: |
        cd /tmp
        wget -c {{ fs_pkg_url }} -O mfs.tar.gz
        tar -xzvf mfs.tar.gz
        cd {{ fs_folder }}
        ./configure --prefix=/usr --sysconfdir=/etc/moosefs --localstatedir=/var/lib --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --disable-mfsmount
        make
        make install
    - cwd: /tmp
    - shell: true
    - timeout: 300
feiming commented 10 years ago

Replicated this error on another Centos box

[INFO    ] Running state [cd /tmp
wget -c http://moosefs.org/tl_files/mfscode/mfs-1.6.27-5.tar.gz -O mfs.tar.gz
tar -xzvf mfs.tar.gz
cd mfs-1.6.27
./configure --prefix=/usr --sysconfdir=/etc/moosefs --localstatedir=/var/lib --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --disable-mfsmount
make
make install
] at time 01:40:19.335165
[INFO    ] Executing state cmd.run for cd /tmp
wget -c http://moosefs.org/tl_files/mfscode/mfs-1.6.27-5.tar.gz -O mfs.tar.gz
tar -xzvf mfs.tar.gz
cd mfs-1.6.27
./configure --prefix=/usr --sysconfdir=/etc/moosefs --localstatedir=/var/lib --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --disable-mfsmount
make
make install

[ERROR   ] An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python2.6/site-packages/salt/state.py", line 1371, in call
    **cdata['kwargs'])
  File "/usr/lib/python2.6/site-packages/salt/states/cmd.py", line 589, in run
    name, timeout=timeout, **cmd_kwargs
  File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 803, in run_all
    saltenv=saltenv)
  File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 261, in _run
    if not os.path.isfile(shell) or not os.access(shell, os.X_OK):
  File "/usr/lib/python2.6/genericpath.py", line 29, in isfile
    st = os.stat(path)
TypeError: coercing to Unicode: need string or buffer, bool found
s0undt3ch commented 10 years ago

I know salt could explain better what happened but the trace actually tells us the issue.

Shell is meant to select a different shell to use, not to say that you want to use a shell.

Pedro Algarvio @ Phone

----- Reply message ----- From: "Fabian Chong" notifications@github.com To: "saltstack/salt" salt@noreply.github.com Subject: [salt] cmd.run/cmd.script getting TypeError: coercing to Unicode: need string or buffer, bool found (#12400) Date: Wed, Apr 30, 2014 07:06 I had tried with cmd.run and cmd.script. Both gave the same error as below.

This is the error message:

[root@experiment moosefs]# salt-call --local state.highstate -l debug ... ... ... ID: salt://moosefs/files/install_script.sh Function: cmd.script Result: False Comment: An exception occurred in this state: Traceback (most recent call last): File "/usr/lib/python2.6/site-packages/salt/state.py", line 1371, in call cdata['kwargs']) File "/usr/lib/python2.6/site-packages/salt/states/cmd.py", line 749, in script cmd_all = salt['cmd.script'](source, cmd_kwargs) File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 995, in script saltenv=saltenv) File "/usr/lib/python2.6/site-packages/salt/modules/cmdmod.py", line 261, in _run if not os.path.isfile(shell) or not os.access(shell, os.X_OK): File "/usr/lib64/python2.6/genericpath.py", line 29, in isfile st = os.stat(path) TypeError: coercing to Unicode: need string or buffer, bool found Changes:

I'm running a masterless Salt. This is the state file and other related info:

[root@experiment moosefs]# cat master.sls
{% from "moosefs/map.jinja" import moosefs with context %}

include:

salt://moosefs/files/install_script.sh: cmd.script:

[root@experiment moosefs]# cat files/install_script.sh

!/bin/bash

cd /tmp wget -c http://moosefs.org/tl_files/mfscode/mfs-1.6.27-5.tar.gz tar xzvf mfs-1.6.27-5.tar.gz cd mfs-1.6.27 ./configure --prefix=/usr --sysconfdir=/etc/moosefs --localstatedir=/var/lib --with-default-user=mfs --with-default-group=mfs --disable-mfschunkserver --disable-mfsmount make make install

[root@experiment moosefs]# salt-minion --version salt-minion 2014.1.0 [root@experiment moosefs]# uname -a Linux experiment 2.6.32-431.11.2.el6.x86_64 #1 SMP Tue Mar 25 19:59:55 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

— Reply to this email directly or view it on GitHub.

feiming commented 10 years ago

thanks. i followed the wrong tutorial

s0undt3ch commented 10 years ago

Can you paste a link to such tutorial? If its ours we need to fix it.

Pedro Algarvio @ Phone

----- Reply message ----- From: "Fabian Chong" notifications@github.com To: "saltstack/salt" salt@noreply.github.com Cc: "Pedro Algarvio" pedro@algarvio.me Subject: [salt] cmd.run/cmd.script getting TypeError: coercing to Unicode: need string or buffer, bool found (#12400) Date: Wed, Apr 30, 2014 09:51 thanks. i followed the wrong tutorial

— Reply to this email directly or view it on GitHub.

notpeter commented 10 years ago

One such incorrect example is here: http://stackoverflow.com/questions/21710963/saltstack-for-configure-make-install