Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save 0x00dec0de/b7ff22f57dae59923e5ddb203ebbb749 to your computer and use it in GitHub Desktop.
Save 0x00dec0de/b7ff22f57dae59923e5ddb203ebbb749 to your computer and use it in GitHub Desktop.
[CHEF] Insert a line in a file if it doesn't already exist
line = '127.0.0.1 gateway.internal gateway'
file = Chef::Util::FileEdit.new('/etc/hosts')
file.insert_line_if_no_match(/#{line}/, line)
file.write_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment