only_if interpretation

Hello,

Can anyone explain me why this "“execute” runs ?

execute “dash” do
command "echo dash"
only_if { “ls -l /bin/sh|grep dash” }
end

[2014-01-21T18:53:13+00:00] INFO: Forking chef instance to converge…
[2014-01-21T18:53:13+00:00] INFO: *** Chef 11.8.2 ***
[2014-01-21T18:53:13+00:00] INFO: Chef-client pid: 1656
[2014-01-21T18:53:15+00:00] INFO: Setting the run_list to [“recipe[cassandra::test]”] from JSON
[2014-01-21T18:53:15+00:00] INFO: Run List is [recipe[cassandra::test]]
[2014-01-21T18:53:15+00:00] INFO: Run List expands to [cassandra::test]
[2014-01-21T18:53:15+00:00] INFO: Starting Chef Run for vagrant
[2014-01-21T18:53:15+00:00] INFO: Running start handlers
[2014-01-21T18:53:15+00:00] INFO: Start handlers complete.
[2014-01-21T18:53:18+00:00] INFO: execute[dash] ran successfully
[2014-01-21T18:53:18+00:00] INFO: Chef Run complete in 2.304952258 seconds
[2014-01-21T18:53:18+00:00] INFO: Running report handlers
[2014-01-21T18:53:18+00:00] INFO: Report handlers complete
[2014-01-21T18:53:13+00:00] INFO: Forking chef instance to converge…

ls -l /bin/sh|grep dash vagrant@vagrant:~ echo $?
1

I can prevent it from running with a not_if statement, but I don’t understand why the previous only_if doesn’t work :

execute “dash” do
command "echo dash"
not_if { “ls -l /bin/sh|grep bash” }
end

[2014-01-21T18:56:12+00:00] INFO: Forking chef instance to converge…
[2014-01-21T18:56:12+00:00] INFO: *** Chef 11.8.2 ***
[2014-01-21T18:56:12+00:00] INFO: Chef-client pid: 2342
[2014-01-21T18:56:14+00:00] INFO: Setting the run_list to [“recipe[cassandra::test]”] from JSON
[2014-01-21T18:56:14+00:00] INFO: Run List is [recipe[cassandra::test]]
[2014-01-21T18:56:14+00:00] INFO: Run List expands to [cassandra::test]
[2014-01-21T18:56:14+00:00] INFO: Starting Chef Run for vagrant
[2014-01-21T18:56:14+00:00] INFO: Running start handlers
[2014-01-21T18:56:14+00:00] INFO: Start handlers complete.
[2014-01-21T18:56:16+00:00] INFO: Chef Run complete in 1.273026178 seconds
[2014-01-21T18:56:16+00:00] INFO: Running report handlers
[2014-01-21T18:56:16+00:00] INFO: Report handlers complete
[2014-01-21T18:56:12+00:00] INFO: Forking chef instance to converge…

ls -l /bin/sh|grep bash lrwxrwxrwx 1 root root 4 Jan 21 17:39 /bin/sh -> bash echo $?
0

Is there anything wrong in my only_if statement that make it runs while it shouldn’t ?

Thanks

Cyril SCETBON

By wrapping the quotes in braces, you have created a ruby block, so you are only testing the creation of a string, rather than the evaluation of a command:

You want:

only_if "ls -l /bin/sh | grep dash"

On Jan 21, 2014, at 2:25 PM, Cyril Scetbon cyril.scetbon@free.fr wrote:

Hello,

Can anyone explain me why this ""execute" runs ?

execute "dash" do
command "echo dash"
only_if { "ls -l /bin/sh|grep dash" }
end

[2014-01-21T18:53:13+00:00] INFO: Forking chef instance to converge...
[2014-01-21T18:53:13+00:00] INFO: *** Chef 11.8.2 ***
[2014-01-21T18:53:13+00:00] INFO: Chef-client pid: 1656
[2014-01-21T18:53:15+00:00] INFO: Setting the run_list to ["recipe[cassandra::test]"] from JSON
[2014-01-21T18:53:15+00:00] INFO: Run List is [recipe[cassandra::test]]
[2014-01-21T18:53:15+00:00] INFO: Run List expands to [cassandra::test]
[2014-01-21T18:53:15+00:00] INFO: Starting Chef Run for vagrant
[2014-01-21T18:53:15+00:00] INFO: Running start handlers
[2014-01-21T18:53:15+00:00] INFO: Start handlers complete.
[2014-01-21T18:53:18+00:00] INFO: execute[dash] ran successfully
[2014-01-21T18:53:18+00:00] INFO: Chef Run complete in 2.304952258 seconds
[2014-01-21T18:53:18+00:00] INFO: Running report handlers
[2014-01-21T18:53:18+00:00] INFO: Report handlers complete
[2014-01-21T18:53:13+00:00] INFO: Forking chef instance to converge...

$ ls -l /bin/sh|grep dash
vagrant@vagrant:~$ echo $?
1

I can prevent it from running with a not_if statement, but I don't understand why the previous only_if doesn't work :

execute "dash" do
command "echo dash"
not_if { "ls -l /bin/sh|grep bash" }
end

[2014-01-21T18:56:12+00:00] INFO: Forking chef instance to converge...
[2014-01-21T18:56:12+00:00] INFO: *** Chef 11.8.2 ***
[2014-01-21T18:56:12+00:00] INFO: Chef-client pid: 2342
[2014-01-21T18:56:14+00:00] INFO: Setting the run_list to ["recipe[cassandra::test]"] from JSON
[2014-01-21T18:56:14+00:00] INFO: Run List is [recipe[cassandra::test]]
[2014-01-21T18:56:14+00:00] INFO: Run List expands to [cassandra::test]
[2014-01-21T18:56:14+00:00] INFO: Starting Chef Run for vagrant
[2014-01-21T18:56:14+00:00] INFO: Running start handlers
[2014-01-21T18:56:14+00:00] INFO: Start handlers complete.
[2014-01-21T18:56:16+00:00] INFO: Chef Run complete in 1.273026178 seconds
[2014-01-21T18:56:16+00:00] INFO: Running report handlers
[2014-01-21T18:56:16+00:00] INFO: Report handlers complete
[2014-01-21T18:56:12+00:00] INFO: Forking chef instance to converge...

$ ls -l /bin/sh|grep bash
lrwxrwxrwx 1 root root 4 Jan 21 17:39 /bin/sh -> bash
$ echo $?
0

Is there anything wrong in my only_if statement that make it runs while it shouldn't ?

Thanks

Cyril SCETBON

not_if and onlu_if when invoked with a block (as in ur case) is evaluated a
ruby code , if invoked with a string evaluated as a command.

On Tue, Jan 21, 2014 at 11:25 AM, Cyril Scetbon cyril.scetbon@free.frwrote:

Hello,

Can anyone explain me why this ""execute" runs ?

execute "dash" do
command "echo dash"
only_if { "ls -l /bin/sh|grep dash" }
end

[2014-01-21T18:53:13+00:00] INFO: Forking chef instance to converge...
[2014-01-21T18:53:13+00:00] INFO: *** Chef 11.8.2 ***
[2014-01-21T18:53:13+00:00] INFO: Chef-client pid: 1656
[2014-01-21T18:53:15+00:00] INFO: Setting the run_list to
["recipe[cassandra::test]"] from JSON
[2014-01-21T18:53:15+00:00] INFO: Run List is [recipe[cassandra::test]]
[2014-01-21T18:53:15+00:00] INFO: Run List expands to [cassandra::test]
[2014-01-21T18:53:15+00:00] INFO: Starting Chef Run for vagrant
[2014-01-21T18:53:15+00:00] INFO: Running start handlers
[2014-01-21T18:53:15+00:00] INFO: Start handlers complete.
[2014-01-21T18:53:18+00:00] INFO: execute[dash] ran successfully
[2014-01-21T18:53:18+00:00] INFO: Chef Run complete in 2.304952258 seconds
[2014-01-21T18:53:18+00:00] INFO: Running report handlers
[2014-01-21T18:53:18+00:00] INFO: Report handlers complete
[2014-01-21T18:53:13+00:00] INFO: Forking chef instance to converge...

$ ls -l /bin/sh|grep dash
vagrant@vagrant:~$ echo $?
1

I can prevent it from running with a not_if statement, but I don't
understand why the previous only_if doesn't work :

execute "dash" do
command "echo dash"
not_if { "ls -l /bin/sh|grep bash" }
end

[2014-01-21T18:56:12+00:00] INFO: Forking chef instance to converge...
[2014-01-21T18:56:12+00:00] INFO: *** Chef 11.8.2 ***
[2014-01-21T18:56:12+00:00] INFO: Chef-client pid: 2342
[2014-01-21T18:56:14+00:00] INFO: Setting the run_list to
["recipe[cassandra::test]"] from JSON
[2014-01-21T18:56:14+00:00] INFO: Run List is [recipe[cassandra::test]]
[2014-01-21T18:56:14+00:00] INFO: Run List expands to [cassandra::test]
[2014-01-21T18:56:14+00:00] INFO: Starting Chef Run for vagrant
[2014-01-21T18:56:14+00:00] INFO: Running start handlers
[2014-01-21T18:56:14+00:00] INFO: Start handlers complete.
[2014-01-21T18:56:16+00:00] INFO: Chef Run complete in 1.273026178 seconds
[2014-01-21T18:56:16+00:00] INFO: Running report handlers
[2014-01-21T18:56:16+00:00] INFO: Report handlers complete
[2014-01-21T18:56:12+00:00] INFO: Forking chef instance to converge...

$ ls -l /bin/sh|grep bash
lrwxrwxrwx 1 root root 4 Jan 21 17:39 /bin/sh -> bash
$ echo $?
0

Is there anything wrong in my only_if statement that make it runs while it
shouldn't ?

Thanks

Cyril SCETBON

AAAAAAAHHHH

thanks guys :slight_smile:

Cyril SCETBON

On 21 Jan 2014, at 20:32, Ranjib Dey dey.ranjib@gmail.com wrote:

not_if and onlu_if when invoked with a block (as in ur case) is evaluated a ruby code , if invoked with a string evaluated as a command.

On Tue, Jan 21, 2014 at 11:25 AM, Cyril Scetbon cyril.scetbon@free.fr wrote:
Hello,

Can anyone explain me why this ""execute" runs ?

execute "dash" do
command "echo dash"
only_if { "ls -l /bin/sh|grep dash" }
end

[2014-01-21T18:53:13+00:00] INFO: Forking chef instance to converge...
[2014-01-21T18:53:13+00:00] INFO: *** Chef 11.8.2 ***
[2014-01-21T18:53:13+00:00] INFO: Chef-client pid: 1656
[2014-01-21T18:53:15+00:00] INFO: Setting the run_list to ["recipe[cassandra::test]"] from JSON
[2014-01-21T18:53:15+00:00] INFO: Run List is [recipe[cassandra::test]]
[2014-01-21T18:53:15+00:00] INFO: Run List expands to [cassandra::test]
[2014-01-21T18:53:15+00:00] INFO: Starting Chef Run for vagrant
[2014-01-21T18:53:15+00:00] INFO: Running start handlers
[2014-01-21T18:53:15+00:00] INFO: Start handlers complete.
[2014-01-21T18:53:18+00:00] INFO: execute[dash] ran successfully
[2014-01-21T18:53:18+00:00] INFO: Chef Run complete in 2.304952258 seconds
[2014-01-21T18:53:18+00:00] INFO: Running report handlers
[2014-01-21T18:53:18+00:00] INFO: Report handlers complete
[2014-01-21T18:53:13+00:00] INFO: Forking chef instance to converge...

$ ls -l /bin/sh|grep dash
vagrant@vagrant:~$ echo $?
1

I can prevent it from running with a not_if statement, but I don't understand why the previous only_if doesn't work :

execute "dash" do
command "echo dash"
not_if { "ls -l /bin/sh|grep bash" }
end

[2014-01-21T18:56:12+00:00] INFO: Forking chef instance to converge...
[2014-01-21T18:56:12+00:00] INFO: *** Chef 11.8.2 ***
[2014-01-21T18:56:12+00:00] INFO: Chef-client pid: 2342
[2014-01-21T18:56:14+00:00] INFO: Setting the run_list to ["recipe[cassandra::test]"] from JSON
[2014-01-21T18:56:14+00:00] INFO: Run List is [recipe[cassandra::test]]
[2014-01-21T18:56:14+00:00] INFO: Run List expands to [cassandra::test]
[2014-01-21T18:56:14+00:00] INFO: Starting Chef Run for vagrant
[2014-01-21T18:56:14+00:00] INFO: Running start handlers
[2014-01-21T18:56:14+00:00] INFO: Start handlers complete.
[2014-01-21T18:56:16+00:00] INFO: Chef Run complete in 1.273026178 seconds
[2014-01-21T18:56:16+00:00] INFO: Running report handlers
[2014-01-21T18:56:16+00:00] INFO: Report handlers complete
[2014-01-21T18:56:12+00:00] INFO: Forking chef instance to converge...

$ ls -l /bin/sh|grep bash
lrwxrwxrwx 1 root root 4 Jan 21 17:39 /bin/sh -> bash
$ echo $?
0

Is there anything wrong in my only_if statement that make it runs while it shouldn't ?

Thanks

Cyril SCETBON