Contents

Running python script in Chef

Contents

In Chef, Ruby DSL (Domain Specific Language) refers to the Ruby-based syntax that is used to write recipes and resources for configuring and managing infrastructure. Chef is a configuration management tool that uses Ruby as its primary programming language.

Using the Ruby DSL, Chef allows users to write code that defines the desired state of infrastructure components, such as servers and applications. The DSL provides a set of Ruby-based resources that can be used to configure various aspects of these components, such as packages, services, files, and users.

Create file with indentations (python, etc)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# file with data to read
file_name = 'file.txt'
# Create shell file to read above
file '/tmp/somefile.sh'
  content <<-EOF.gsub(/^\s+\//, '')
    |#!/usr/bin/env python3
    |
    |import json
    |
    |with open('#{file_name}') as f:
    |  d = json.load(f)
    |  print(d)
    |
    EOF
end