Chef for Block in ansible 中的等效资源是什么?
What is the equivalent resource in Chef for Block in ansible?
我有一些使用 Block 模块的 ansible 剧本,同样我想在 Chef 中重写。但无法在 Chef 中找到等效资源。
示例源代码:
tasks:
- name: Handle the error
block:
- debug:
msg: 'I execute normally'
- name: i force a failure
command: /bin/false
- debug:
msg: 'I never execute, due to the above task failing, :-('
rescue:
- debug:
msg: 'I caught an error, can do stuff here to fix it, :-)'
注意:以上几行是示例代码。它可以是任何一行代码。但我需要知道我可以使用哪个 chef 资源来替换块语法?
Blocks
允许对任务进行逻辑分组和进行中的错误处理。主要用于将单个条件应用于多个任务,这可以通过 Chef 中的 If
条件来实现。
if node[:platform_family].include?("rhel")
package 'httpd'
service 'httpd' do
action [:enable, :start]
end
end
没有直接的等效项,至少对于 rescue
功能而言是这样。对于分组,您只需使用正常的 Ruby 编码实践。
我有一些使用 Block 模块的 ansible 剧本,同样我想在 Chef 中重写。但无法在 Chef 中找到等效资源。
示例源代码:
tasks:
- name: Handle the error
block:
- debug:
msg: 'I execute normally'
- name: i force a failure
command: /bin/false
- debug:
msg: 'I never execute, due to the above task failing, :-('
rescue:
- debug:
msg: 'I caught an error, can do stuff here to fix it, :-)'
注意:以上几行是示例代码。它可以是任何一行代码。但我需要知道我可以使用哪个 chef 资源来替换块语法?
Blocks
允许对任务进行逻辑分组和进行中的错误处理。主要用于将单个条件应用于多个任务,这可以通过 Chef 中的 If
条件来实现。
if node[:platform_family].include?("rhel")
package 'httpd'
service 'httpd' do
action [:enable, :start]
end
end
没有直接的等效项,至少对于 rescue
功能而言是这样。对于分组,您只需使用正常的 Ruby 编码实践。