Error in running python script through python resource

Hi all,

I am trying to run a simple python script using python resource of chef-cookbook. Here is what my recipe looks like:

filename = "test.py"
python “excute_file” do
cwd '/home/peeyush/'
code <<-EOH
python #{filename}
EOH
action :run
end

The error I am getting is:

Recipe: hellochef::default

  • python[excute_file] action run
    ================================================================================
    Error executing action run on resource ‘python[excute_file]’
    ================================================================================

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received ‘1’
---- Begin output of “python” “/tmp/chef-script20140306-20614-1mjuchc” ----
STDOUT:
STDERR: File “/tmp/chef-script20140306-20614-1mjuchc”, line 1
python test.py
^
SyntaxError: invalid syntax
---- End output of “python” “/tmp/chef-script20140306-20614-1mjuchc” ----
Ran “python” “/tmp/chef-script20140306-20614-1mjuchc” returned 1

Resource Declaration:

In /home/peeyush/chef/cookbook/hellochef/recipes/default.rb

17: python “excute_file” do
18: cwd '/home/peeyush/'
19: code <<-EOH
20: python #{filename}
21: EOH
22: action :run
23: end

Compiled Resource:

Declared in /home/peeyush/chef/cookbook/hellochef/recipes/default.rb:17:in `from_file’

python(“excute_file”) do
action [:run]
retries 0
retry_delay 2
command "“python” “/tmp/chef-script20140306-20614-1mjuchc”"
backup 5
cwd "/home/peeyush/"
returns 0
code "python test.py\n"
interpreter "python"
cookbook_name :hellochef
recipe_name "default"
end

Running handlers:
[2014-03-06T17:49:48+05:30] ERROR: Running exception handlers
Running handlers complete

[2014-03-06T17:49:48+05:30] ERROR: Exception handlers complete
[2014-03-06T17:49:48+05:30] FATAL: Stacktrace dumped to /home/peeyush/chef/chef-stacktrace.out
Chef Client failed. 0 resources updated in 1.216862761 seconds
[2014-03-06T17:49:48+05:30] ERROR: python[excute_file] (hellochef::default line 17) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘1’
---- Begin output of “python” “/tmp/chef-script20140306-20614-1mjuchc” ----
STDOUT:
STDERR: File “/tmp/chef-script20140306-20614-1mjuchc”, line 1
python test.py
^
SyntaxError: invalid syntax
---- End output of “python” “/tmp/chef-script20140306-20614-1mjuchc” ----
Ran “python” “/tmp/chef-script20140306-20614-1mjuchc” returned 1
[2014-03-06T17:49:48+05:30] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)

I am not sure what I am doing wrong as there is no example to run a python script. Please help me resolve this issue.

Thanks,

~Peeyush Gupta

You are generating a python script that contains the code

python test.py

which will cause an error when passed to the Python interpreter:

$ cat test.py
python test.py
$ python test.py
File "test.py", line 1
python test.py
^
SyntaxError: invalid syntax

If you want to execute an external script, just use the 'execute'
resource. However, if you want to execute in-line python, then just
write the Python code in the "code" attribute.

  • Julian

On Thu, Mar 6, 2014 at 7:24 AM, Peeyush Gupta gpeeyush@ymail.com wrote:

Hi all,

I am trying to run a simple python script using python resource of
chef-cookbook. Here is what my recipe looks like:

filename = "test.py"
python "excute_file" do
cwd '/home/peeyush/'
code <<-EOH
python #{filename}
EOH
action :run
end

The error I am getting is:

Recipe: hellochef::default

  • python[excute_file] action run
    ================================================================================
    Error executing action run on resource 'python[excute_file]'
    ================================================================================

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received '1'
---- Begin output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
STDOUT:
STDERR: File "/tmp/chef-script20140306-20614-1mjuchc", line 1
python test.py
^
SyntaxError: invalid syntax
---- End output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
Ran "python" "/tmp/chef-script20140306-20614-1mjuchc" returned 1

Resource Declaration:

In /home/peeyush/chef/cookbook/hellochef/recipes/default.rb

17: python "excute_file" do
18: cwd '/home/peeyush/'
19: code <<-EOH
20: python #{filename}
21: EOH
22: action :run
23: end

Compiled Resource:

Declared in /home/peeyush/chef/cookbook/hellochef/recipes/default.rb:17:in

`from_file'

python("excute_file") do
action [:run]
retries 0
retry_delay 2
command ""python" "/tmp/chef-script20140306-20614-1mjuchc""
backup 5
cwd "/home/peeyush/"
returns 0
code "python test.py\n"
interpreter "python"
cookbook_name :hellochef
recipe_name "default"
end

Running handlers:
[2014-03-06T17:49:48+05:30] ERROR: Running exception handlers
Running handlers complete

[2014-03-06T17:49:48+05:30] ERROR: Exception handlers complete
[2014-03-06T17:49:48+05:30] FATAL: Stacktrace dumped to
/home/peeyush/chef/chef-stacktrace.out
Chef Client failed. 0 resources updated in 1.216862761 seconds
[2014-03-06T17:49:48+05:30] ERROR: python[excute_file] (hellochef::default
line 17) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected
process to exit with [0], but received '1'
---- Begin output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
STDOUT:
STDERR: File "/tmp/chef-script20140306-20614-1mjuchc", line 1
python test.py
^
SyntaxError: invalid syntax
---- End output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
Ran "python" "/tmp/chef-script20140306-20614-1mjuchc" returned 1
[2014-03-06T17:49:48+05:30] FATAL: Chef::Exceptions::ChildConvergeError:
Chef run process exited unsuccessfully (exit code 1)

I am not sure what I am doing wrong as there is no example to run a python
script. Please help me resolve this issue.

Thanks,

~Peeyush Gupta

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

This was asked and answered on Stackoverflow: Error in running python script using chef - Stack Overflow

Thanks,
Seth

On Mar 6, 2014, at 12:09 PM, Julian C. Dunn jdunn@aquezada.com wrote:

You are generating a python script that contains the code

python test.py

which will cause an error when passed to the Python interpreter:

$ cat test.py
python test.py
$ python test.py
File "test.py", line 1
python test.py
^
SyntaxError: invalid syntax

If you want to execute an external script, just use the 'execute'
resource. However, if you want to execute in-line python, then just
write the Python code in the "code" attribute.

  • Julian

On Thu, Mar 6, 2014 at 7:24 AM, Peeyush Gupta gpeeyush@ymail.com wrote:

Hi all,

I am trying to run a simple python script using python resource of
chef-cookbook. Here is what my recipe looks like:

filename = "test.py"
python "excute_file" do
cwd '/home/peeyush/'
code <<-EOH
python #{filename}
EOH
action :run
end

The error I am getting is:

Recipe: hellochef::default

  • python[excute_file] action run
    ================================================================================
    Error executing action run on resource 'python[excute_file]'
    ================================================================================

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received '1'
---- Begin output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
STDOUT:
STDERR: File "/tmp/chef-script20140306-20614-1mjuchc", line 1
python test.py
^
SyntaxError: invalid syntax
---- End output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
Ran "python" "/tmp/chef-script20140306-20614-1mjuchc" returned 1

Resource Declaration:

In /home/peeyush/chef/cookbook/hellochef/recipes/default.rb

17: python "excute_file" do
18: cwd '/home/peeyush/'
19: code <<-EOH
20: python #{filename}
21: EOH
22: action :run
23: end

Compiled Resource:

Declared in /home/peeyush/chef/cookbook/hellochef/recipes/default.rb:17:in

`from_file'

python("excute_file") do
action [:run]
retries 0
retry_delay 2
command ""python" "/tmp/chef-script20140306-20614-1mjuchc""
backup 5
cwd "/home/peeyush/"
returns 0
code "python test.py\n"
interpreter "python"
cookbook_name :hellochef
recipe_name "default"
end

Running handlers:
[2014-03-06T17:49:48+05:30] ERROR: Running exception handlers
Running handlers complete

[2014-03-06T17:49:48+05:30] ERROR: Exception handlers complete
[2014-03-06T17:49:48+05:30] FATAL: Stacktrace dumped to
/home/peeyush/chef/chef-stacktrace.out
Chef Client failed. 0 resources updated in 1.216862761 seconds
[2014-03-06T17:49:48+05:30] ERROR: python[excute_file] (hellochef::default
line 17) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected
process to exit with [0], but received '1'
---- Begin output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
STDOUT:
STDERR: File "/tmp/chef-script20140306-20614-1mjuchc", line 1
python test.py
^
SyntaxError: invalid syntax
---- End output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
Ran "python" "/tmp/chef-script20140306-20614-1mjuchc" returned 1
[2014-03-06T17:49:48+05:30] FATAL: Chef::Exceptions::ChildConvergeError:
Chef run process exited unsuccessfully (exit code 1)

I am not sure what I am doing wrong as there is no example to run a python
script. Please help me resolve this issue.

Thanks,

~Peeyush Gupta

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]

Thank you guys! Execute resource worked!

Thanks,
~Peeyush Gupta

On Friday, 7 March 2014 9:40 PM, Seth Vargo sethvargo@getchef.com wrote:

This was asked and answered on Stackoverflow: Error in running python script using chef - Stack Overflow

Thanks,
Seth

On Mar 6, 2014, at 12:09 PM, Julian C. Dunn jdunn@aquezada.com wrote:

You are generating a python script that contains the code

python test.py

which will cause an error when passed to the Python interpreter:

$ cat test.py
python test.py
$ python test.py
File "test.py", line 1
python test.py
^
SyntaxError: invalid syntax

If you want to execute an external script, just use the 'execute'
resource. However, if you want to execute in-line python, then just
write the Python code in the "code" attribute.

  • Julian

On Thu, Mar 6, 2014 at 7:24 AM, Peeyush Gupta gpeeyush@ymail.com wrote:

Hi all,

I am trying to run a simple python script using python resource of
chef-cookbook. Here is what my recipe looks like:

filename = "test.py"
python "excute_file" do
cwd '/home/peeyush/'
code <<-EOH
python #{filename}
EOH
action :run
end

The error I am getting is:

Recipe: hellochef::default

  • python[excute_file] action run
    ================================================================================
    Error executing action run on resource 'python[excute_file]'
    ================================================================================

Mixlib::ShellOut::ShellCommandFailed

Expected process to exit with [0], but received '1'
---- Begin output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
STDOUT:
STDERR: File "/tmp/chef-script20140306-20614-1mjuchc", line 1
python test.py
^
SyntaxError: invalid syntax
---- End output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
Ran "python" "/tmp/chef-script20140306-20614-1mjuchc" returned 1

Resource Declaration:

In /home/peeyush/chef/cookbook/hellochef/recipes/default.rb

17: python "excute_file" do
18: cwd '/home/peeyush/'
19: code <<-EOH
20: python #{filename}
21: EOH
22: action :run
23: end

Compiled Resource:

Declared in /home/peeyush/chef/cookbook/hellochef/recipes/default.rb:17:in

`from_file'

python("excute_file") do
action [:run]
retries 0
retry_delay 2
command ""python" "/tmp/chef-script20140306-20614-1mjuchc""
backup 5
cwd "/home/peeyush/"
returns 0
code "python test.py\n"
interpreter "python"
cookbook_name :hellochef
recipe_name "default"
end

Running handlers:
[2014-03-06T17:49:48+05:30] ERROR: Running exception handlers
Running handlers complete

[2014-03-06T17:49:48+05:30] ERROR: Exception handlers complete
[2014-03-06T17:49:48+05:30] FATAL: Stacktrace dumped to
/home/peeyush/chef/chef-stacktrace.out
Chef Client failed. 0 resources updated in 1.216862761 seconds
[2014-03-06T17:49:48+05:30] ERROR: python[excute_file] (hellochef::default
line 17) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected
process to exit with [0], but received '1'
---- Begin output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
STDOUT:
STDERR: File "/tmp/chef-script20140306-20614-1mjuchc", line 1
python test.py
^
SyntaxError: invalid syntax
---- End output of "python" "/tmp/chef-script20140306-20614-1mjuchc" ----
Ran "python" "/tmp/chef-script20140306-20614-1mjuchc" returned 1
[2014-03-06T17:49:48+05:30] FATAL: Chef::Exceptions::ChildConvergeError:
Chef run process exited unsuccessfully (exit code 1)

I am not sure what I am doing wrong as there is no example to run a python
script. Please help me resolve this issue.

Thanks,

~Peeyush Gupta

--
[ Julian C. Dunn jdunn@aquezada.com * Sorry, I'm ]
[ WWW: http://www.aquezada.com/staff/julian * only Web 1.0 ]
[ gopher://sdf.org/1/users/keymaker/ * compliant! ]
[ PGP: 91B3 7A9D 683C 7C16 715F 442C 6065 D533 FDC2 05B9 ]