forked from mrtaddy/omg-macbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
82 lines (70 loc) · 1.77 KB
/
Rakefile
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require 'yaml'
namespace :xcode do
task :lisence do
sh 'which xcodebuild' do |ok, _status|
break unless ok
sh 'sudo xcodebuild -license'
end
end
task :install do
sh 'which xcode-select' do |ok, _status|
break unless ok
sh 'xcode-select --install'
end
end
end
namespace :brew do
task :install do
sh 'which brew' do |ok, _status|
break if ok
sh '/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"'
end
end
task ansible: :install do
sh 'which ansible' do |ok, _status|
break if ok
sh 'brew install ansible'
end
end
end
namespace :ansible do
def roles
@roles ||= YAML.load_file('requirements.yml').map { |role| role['src'] }
end
def installed_roles
@installed_roles ||= YAML.load(`ansible-galaxy list`).map do |line|
line.split(',').first
end
rescue
[]
end
task :galaxy do
sh 'which ansible-galaxy' do |ok, _status|
break unless ok
(roles - installed_roles).each do |role|
sh "ansible-galaxy install #{role}"
end
end
end
task playbook: :galaxy do
sh 'which ansible-playbook' do |ok, _status|
break unless ok
sh 'ansible-playbook -i hosts -vv localhost.yml'
end
end
end
namespace :playbook do
def tags
@tags ||= YAML.load_file('localhost.yml').first['roles'].flat_map { |role| role["tags"] }.compact.uniq
end
tags.each do |tag|
desc "ansible-playbook -i hosts -vv localhost.yml -t #{tag}"
task tag.to_sym => 'ansible:galaxy' do
sh "ansible-playbook -i hosts -vv localhost.yml -t #{tag}"
end
end
end
desc 'setup ansible'
task :setup => "brew:ansible"
desc 'ansible-playbook -i hosts -vv localhost.yml'
task :default => "ansible:playbook"