Help with yum_package flush_cache optiop

https://docs.chef.io/resource_package.html

Above documentation for flush_cache gives a syntax error. What is the correct syntax?

Chris

Can you show us what you have and the error you’re getting?

The format should be something like:

Works in all Rubies

yum_package 'some-package' do#...
flush_cache({ :before => false, :after => false })#...end

Also works in Ruby >= 1.9

yum_package 'some-package' do#...
flush_cache({ before: false, after: false })#...end

Ordinarily, the parentheses on resource attributes aren’t required, but
without them, in this case, the Ruby syntax parser has no way of
differentiating between a hash argument and a block argument. That is, this
does not work:

yum_package 'some-package' do#...
flush_cache { :before => false, :after => false }#...end

syntax error, unexpected =>, expecting '}'# flush_cache { :before

=> false, :after => false }# ^

If I had to guess, perhaps this is the error you’re getting?

Matt Moretti
UMTS IT

On Thu, Jun 4, 2015 at 10:55 PM, Fouts, Chris Chris.Fouts@sensus.com
wrote:

package Resource

Above documentation for flush_cache gives a syntax error. What is the
correct syntax?

Chris

The correct syntax, after playing with it is

package ‘some_rpm’ do
flush_cache [ :before, :after ]
end

From: Matthew Moretti [mailto:werebus@gmail.com]
Sent: Friday, June 05, 2015 1:34 PM
To: chef@lists.opscode.com
Subject: [chef] Re: help with yum_package flush_cache optiop

Can you show us what you have and the error you’re getting?

The format should be something like:

Works in all Rubies

yum_package ‘some-package’ do

#…

flush_cache({ :before => false, :after => false })

#…

end

Also works in Ruby >= 1.9

yum_package ‘some-package’ do

#…

flush_cache({ before: false, after: false })

#…

end

Ordinarily, the parentheses on resource attributes aren’t required, but without them, in this case, the Ruby syntax parser has no way of differentiating between a hash argument and a block argument. That is, this does not work:

yum_package ‘some-package’ do

#…

flush_cache { :before => false, :after => false }

#…

end

syntax error, unexpected =>, expecting ‘}’

flush_cache { :before => false, :after => false }

^

If I had to guess, perhaps this is the error you’re getting?

Matt Moretti
UMTS IT

On Thu, Jun 4, 2015 at 10:55 PM, Fouts, Chris <Chris.Fouts@sensus.commailto:Chris.Fouts@sensus.com> wrote:
https://docs.chef.io/resource_package.html

Above documentation for flush_cache gives a syntax error. What is the correct syntax?

Chris

Yes, that apparently works too. The code in the resource appears to have some
logic
https://github.com/chef/chef/blob/master/lib/chef/resource/yum_package.rb#L45-L46
in it to handle being given an array instead of the hash. Although that
feature is missing from the docs.

Matt Moretti

On Fri, Jun 5, 2015 at 4:32 PM, Fouts, Chris Chris.Fouts@sensus.com wrote:

The correct syntax, after playing with it is

package ‘some_rpm’ do

flush_cache [ :before, :after ]

end

From: Matthew Moretti [mailto:werebus@gmail.com]
Sent: Friday, June 05, 2015 1:34 PM
To: chef@lists.opscode.com
Subject: [chef] Re: help with yum_package flush_cache optiop

Can you show us what you have and the error you’re getting?

The format should be something like:

# Works in all Rubies

yum_package 'some-package' do

#...

flush_cache({ :before => false, :after => false })

#...

end

# Also works in Ruby >= 1.9

yum_package 'some-package' do

#...

flush_cache({ before: false, after: false })

#...

end

Ordinarily, the parentheses on resource attributes aren’t required, but
without them, in this case, the Ruby syntax parser has no way of
differentiating between a hash argument and a block argument. That is, this
does not work:

yum_package 'some-package' do

#...

flush_cache { :before => false, :after => false }

#...

end

# syntax error, unexpected =>, expecting '}'

# flush_cache { :before => false, :after => false }

# ^

If I had to guess, perhaps this is the error you’re getting?

Matt Moretti
UMTS IT

On Thu, Jun 4, 2015 at 10:55 PM, Fouts, Chris Chris.Fouts@sensus.com
wrote:

package Resource

Above documentation for flush_cache gives a syntax error. What is the
correct syntax?

Chris

Can you file an issue against chef-docs?

--
Daniel DeLeo

On Saturday, June 6, 2015 at 12:20 PM, Matthew Moretti wrote:

Yes, that apparently works too. The code in the resource appears to have some logic (https://github.com/chef/chef/blob/master/lib/chef/resource/yum_package.rb#L45-L46) in it to handle being given an array instead of the hash. Although that feature is missing from the docs.

Matt Moretti

On Fri, Jun 5, 2015 at 4:32 PM, Fouts, Chris <Chris.Fouts@sensus.com (mailto:Chris.Fouts@sensus.com)> wrote:

The correct syntax, after playing with it is

package ‘some_rpm’ do
flush_cache [ :before, :after ]
end

From: Matthew Moretti [mailto:werebus@gmail.com]
Sent: Friday, June 05, 2015 1:34 PM
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Re: help with yum_package flush_cache optiop

Can you show us what you have and the error you’re getting?

The format should be something like:

Works in all Rubies

yum_package 'some-package' do
#...
flush_cache({ :before => false, :after => false })
#...
end

Also works in Ruby >= 1.9

yum_package 'some-package' do
#...
flush_cache({ before: false, after: false })
#...
end

Ordinarily, the parentheses on resource attributes aren’t required, but without them, in this case, the Ruby syntax parser has no way of differentiating between a hash argument and a block argument. That is, this does not work:

yum_package 'some-package' do
#...
flush_cache { :before => false, :after => false }
#...
end

syntax error, unexpected =>, expecting '}'

flush_cache { :before => false, :after => false }

^

If I had to guess, perhaps this is the error you’re getting?

Matt Moretti
UMTS IT

On Thu, Jun 4, 2015 at 10:55 PM, Fouts, Chris <Chris.Fouts@sensus.com (mailto:Chris.Fouts@sensus.com)> wrote:
package Resource

Above documentation for flush_cache gives a syntax error. What is the correct syntax?

Chris

Looks like someone beat me to it.

Thanks, James

Matt Moretti

On Mon, Jun 8, 2015 at 11:43 AM, Daniel DeLeo dan@kallistec.com wrote:

Can you file an issue against chef-docs?

Issues · chef-boneyard/chef-web-docs-2016 · GitHub

--
Daniel DeLeo

On Saturday, June 6, 2015 at 12:20 PM, Matthew Moretti wrote:

Yes, that apparently works too. The code in the resource appears to have
some logic (
https://github.com/chef/chef/blob/master/lib/chef/resource/yum_package.rb#L45-L46)
in it to handle being given an array instead of the hash. Although that
feature is missing from the docs.

Matt Moretti

On Fri, Jun 5, 2015 at 4:32 PM, Fouts, Chris <Chris.Fouts@sensus.com
(mailto:Chris.Fouts@sensus.com)> wrote:

The correct syntax, after playing with it is

package ‘some_rpm’ do
flush_cache [ :before, :after ]
end

From: Matthew Moretti [mailto:werebus@gmail.com]
Sent: Friday, June 05, 2015 1:34 PM
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Re: help with yum_package flush_cache optiop

Can you show us what you have and the error you’re getting?

The format should be something like:

Works in all Rubies

yum_package 'some-package' do
#...
flush_cache({ :before => false, :after => false })
#...
end

Also works in Ruby >= 1.9

yum_package 'some-package' do
#...
flush_cache({ before: false, after: false })
#...
end

Ordinarily, the parentheses on resource attributes aren’t required,
but without them, in this case, the Ruby syntax parser has no way of
differentiating between a hash argument and a block argument. That is, this
does not work:

yum_package 'some-package' do
#...
flush_cache { :before => false, :after => false }
#...
end

syntax error, unexpected =>, expecting '}'

flush_cache { :before => false, :after => false }

^

If I had to guess, perhaps this is the error you’re getting?

Matt Moretti
UMTS IT

On Thu, Jun 4, 2015 at 10:55 PM, Fouts, Chris <Chris.Fouts@sensus.com
(mailto:Chris.Fouts@sensus.com)> wrote:
package Resource

Above documentation for flush_cache gives a syntax error. What is the
correct syntax?

Chris