-
Notifications
You must be signed in to change notification settings - Fork 222
/
Copy pathboltdir.rb
51 lines (43 loc) · 1.39 KB
/
boltdir.rb
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# frozen_string_literal: true
require 'pathname'
module Bolt
class Boltdir
BOLTDIR_NAME = 'Boltdir'
attr_reader :path, :config_file, :inventory_file, :modulepath, :hiera_config, :puppetfile, :rerunfile
def self.default_boltdir
Boltdir.new(File.join('~', '.puppetlabs', 'bolt'))
end
# Search recursively up the directory hierarchy for the Boltdir. Look for a
# directory called Boltdir or a file called bolt.yaml (for a control repo
# type Boltdir). Otherwise, repeat the check on each directory up the
# hierarchy, falling back to the default if we reach the root.
def self.find_boltdir(dir)
dir = Pathname.new(dir)
if (dir + BOLTDIR_NAME).directory?
new(dir + BOLTDIR_NAME)
elsif (dir + 'bolt.yaml').file?
new(dir)
elsif dir.root?
default_boltdir
else
find_boltdir(dir.parent)
end
end
def initialize(path)
@path = Pathname.new(path).expand_path
@config_file = @path + 'bolt.yaml'
@inventory_file = @path + 'inventory.yaml'
@modulepath = [(@path + 'modules').to_s, (@path + 'site-modules').to_s, (@path + 'site').to_s]
@hiera_config = @path + 'hiera.yaml'
@puppetfile = @path + 'Puppetfile'
@rerunfile = @path + '.rerun.json'
end
def to_s
@path.to_s
end
def eql?(other)
path == other.path
end
alias == eql?
end
end