summaryrefslogtreecommitdiff
path: root/examples/rake/Rakefile
blob: 27b7e7a088dbde59a6f2c0663e8c7cc1714d2eef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Example: Using RCM with Rake (from a project directory).
#
# Run with:
#   rake setup -- --dry      # dry run, no changes made
#   rake setup -- --debug    # verbose output
#   rake setup               # apply configuration
#
# This example assumes rcm is available via bundler (see Gemfile),
# or you can swap the require for: require_relative '../../lib/dsl'
require 'rcm'

desc 'Apply system configuration'
task :setup do
  configure do
    # Only run on host named 'earth'
    given { hostname is :earth }

    # Create a WireGuard config from an inline ERB template.
    # The 'manage directory' directive creates /tmp/example/wg/ if it is missing.
    file '/tmp/example/wg/wg0.conf' do
      manage directory
      from template

      <<~TEMPLATE
        [Interface]
        Address = <%= "10.0.0.1/24" %>
        ListenPort = 51820
      TEMPLATE
    end

    # Ensure a specific line is present in a hosts file (idempotent).
    file '/tmp/example/hosts.txt' do
      line '192.168.1.101 earth.local'
    end
  end
end