Module: Orats::Commands::Diff::Parse

Included in:
Common, Exec
Defined in:
lib/orats/commands/diff/parse.rb

Instance Method Summary collapse

Instance Method Details

#galaxyfile(contents) ⇒ Object



9
10
11
# File 'lib/orats/commands/diff/parse.rb', line 9

def galaxyfile(contents)
  contents.split
end

#gem_versionObject



5
6
7
# File 'lib/orats/commands/diff/parse.rb', line 5

def gem_version
  "v#{url_to_string(@remote_paths[:version]).match(/'(.*)'/)[1..-1].first}"
end

#hosts(contents) ⇒ Object



13
14
15
# File 'lib/orats/commands/diff/parse.rb', line 13

def hosts(contents)
  contents.scan(/^\[.*\]/)
end

#inventory(contents) ⇒ Object



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
# File 'lib/orats/commands/diff/parse.rb', line 17

def inventory(contents)
  # pluck out all of the values contained with {{ }}
  ansible_variables = contents.scan(/\{\{([^{{}}]*)\}\}/)

  # remove the leading space
  ansible_variables.map! { |line| line.first[0] = '' }

  # match every line that is not a comment and contains a colon
  inventory_variables = contents.scan(/^[^#].*:/)

  inventory_variables.map! do |line|
    # only strip lines that need it
    line.strip! if line.include?(' ') || line.include?("\n")

    # get rid of the trailing colon
    line.chomp(':')

    # if a value of a certain variable has a colon then the regex
    # picks this up as a match. only take the variable name
    # if this happens to occur
    line.split(':').first if line.include?(':')
  end

  (ansible_variables + inventory_variables).uniq.delete_if(&:empty?)
end

#playbook(contents) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/orats/commands/diff/parse.rb', line 43

def playbook(contents)
  roles = contents.scan(/^.*role:.*/)

  roles.map! do |line|
    line.strip! if line.include?(' ') || line.include?("\n")

    role_parts = line.split('role:')

    # start at the actual role name
    line       = role_parts[1]

    if line.include?(',')
      line = line.split(',').first
    end

    line.strip! if line.include?(' ')
  end

  roles.uniq
end