librarian-ansible 1.0.5 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +11 -0
- data/README.md +77 -1
- data/lib/librarian/ansible/source/galaxy.rb +27 -13
- data/lib/librarian/ansible/version.rb +1 -1
- data/spec/functional/ansible/cli_spec.rb +63 -0
- data/spec/integration/ansible/source/git_spec.rb +363 -0
- data/spec/support/project_path.rb +27 -0
- data/spec/support/spec_helper.rb +28 -0
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72c8d1017901562889ad9a7037f3fc503cadf518
|
4
|
+
data.tar.gz: 640bcfe4416e2cc3ff0bab763c7da9fb72a73b05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d799b4e7a4cae5deddd9379c70ee53c28b6e709d9c32d2f8d87816cbc5ed23e241afc013cbd8dcccbca1df842f7b9456eefc006dfcef146802aa9e6cbb73e41
|
7
|
+
data.tar.gz: 6970dac352e1426e85c1a516e0196486fbe6eb9a52a3742fceb6584912102c4dfb1d3c831383d8af619e3031c1feced49f20df4df37fe925fed4c04d730d14cd
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
Librarian-Ansible
|
2
2
|
=================
|
3
3
|
|
4
|
+
[](https://codeclimate.com/github/bcoe/librarian-ansible)
|
5
|
+
[](https://travis-ci.org/bcoe/librarian-ansible)
|
6
|
+
|
4
7
|
Provides bundler-inspired functionality for Ansible roles:
|
5
8
|
|
6
9
|
http://bundler.io/v1.3/rationale.html
|
@@ -104,9 +107,82 @@ And update your Ansiblefile accordingly:
|
|
104
107
|
role "kunik.deploy-upstart-scripts", "1.0.0"
|
105
108
|
```
|
106
109
|
|
110
|
+
### Configuration
|
111
|
+
|
112
|
+
Configuration comes from three sources with the following highest-to-lowest
|
113
|
+
precedence:
|
114
|
+
|
115
|
+
* The local config (`./.librarian/ansible/config`)
|
116
|
+
* The environment
|
117
|
+
* The global config (`~/.librarian/ansible/config`)
|
118
|
+
|
119
|
+
You can inspect the final configuration with:
|
120
|
+
|
121
|
+
$ librarian-ansible config
|
122
|
+
|
123
|
+
You can find out where a particular key is set with:
|
124
|
+
|
125
|
+
$ librarian-ansible config KEY
|
126
|
+
|
127
|
+
You can set a key at the global level with:
|
128
|
+
|
129
|
+
$ librarian-ansible config KEY VALUE --global
|
130
|
+
|
131
|
+
And remove it with:
|
132
|
+
|
133
|
+
$ librarian-ansible config KEY --global --delete
|
134
|
+
|
135
|
+
You can set a key at the local level with:
|
136
|
+
|
137
|
+
$ librarian-ansible config KEY VALUE --local
|
138
|
+
|
139
|
+
And remove it with:
|
140
|
+
|
141
|
+
$ librarian-ansible config KEY --local --delete
|
142
|
+
|
143
|
+
You cannot set or delete environment-level config keys with the CLI.
|
144
|
+
|
145
|
+
Configuration set at either the global or local level will affect subsequent
|
146
|
+
invocations of `librarian-ansible`. Configurations set at the environment level are
|
147
|
+
not saved and will not affect subsequent invocations of `librarian-ansible`.
|
148
|
+
|
149
|
+
You can pass a config at the environment level by taking the original config key
|
150
|
+
and transforming it: replace hyphens (`-`) with underscores (`_`) and periods
|
151
|
+
(`.`) with doubled underscores (`__`), uppercase, and finally prefix with
|
152
|
+
`LIBRARIAN_ANSIBLE_`. For example, to pass a config in the environment for the key
|
153
|
+
`part-one.part-two`, set the environment variable
|
154
|
+
`LIBRARIAN_ANSIBLE_PART_ONE__PART_TWO`.
|
155
|
+
|
156
|
+
Configuration affects how various commands operate.
|
157
|
+
|
158
|
+
* The `path` config sets the roles directory to install to. If a relative
|
159
|
+
path, it is relative to the directory containing the `Ansiblefile`. The
|
160
|
+
equivalent environment variable is `LIBRARIAN_ANSIBLE_PATH`.
|
161
|
+
|
162
|
+
* The `tmp` config sets the cache directory for librarian. If a relative
|
163
|
+
path, it is relative to the directory containing the `Ansiblefile`. The
|
164
|
+
equivalent environment variable is `LIBRARIAN_ANSIBLE_TMP`.
|
165
|
+
|
166
|
+
* The `install.strip-dot-git` config causes the `.git/` directory to be stripped
|
167
|
+
out when installing roles from a git source. This must be set to exactly
|
168
|
+
"1" to cause this behavior. The equivalent environment variable is
|
169
|
+
`LIBRARIAN_ANSIBLE_INSTALL__STRIP_DOT_GIT`.
|
170
|
+
|
171
|
+
Configuration can be set by passing specific options to other commands.
|
172
|
+
|
173
|
+
* The `path` config can be set at the local level by passing the `--path` option
|
174
|
+
to the `install` command. It can be unset at the local level by passing the
|
175
|
+
`--no-path` option to the `install` command. Note that if this is set at the
|
176
|
+
environment or global level then, even if `--no-path` is given as an option,
|
177
|
+
the environment or global config will be used.
|
178
|
+
|
179
|
+
* The `install.strip-dot-git` config can be set at the local level by passing
|
180
|
+
the `--strip-dot-git` option to the `install` command. It can be unset at the
|
181
|
+
local level by passing the `--no-strip-dot-git` option.
|
182
|
+
|
107
183
|
## Contributing
|
108
184
|
|
109
|
-
1. Fork it ( http://github.com
|
185
|
+
1. Fork it ( http://github.com/bcoe/librarian-ansible/fork )
|
110
186
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
111
187
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
112
188
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -31,26 +31,40 @@ module Librarian
|
|
31
31
|
private
|
32
32
|
|
33
33
|
def github_url(uri)
|
34
|
-
|
34
|
+
package = nil
|
35
|
+
# because both name and username can contain dots, we have
|
36
|
+
# to check every combination until package will be found
|
37
|
+
segments = uri.split('.')
|
38
|
+
(0..segments.size - 2).each do |pivot|
|
39
|
+
username = segments[0..pivot].join('.')
|
40
|
+
name = segments[pivot + 1..-1].join('.')
|
41
|
+
package = lookup_package(username, name)
|
42
|
+
end
|
43
|
+
raise Error, "Could not find package: #{uri}" if package.nil?
|
44
|
+
"https://github.com/#{package['github_user']}/#{package['github_repo']}"
|
45
|
+
end
|
35
46
|
|
47
|
+
def lookup_package(username, name)
|
36
48
|
conn = Faraday.new(:url => @@galaxy_api)
|
37
49
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
50
|
+
url = "#{@@galaxy_api}/roles/?name=#{name}&format=json"
|
51
|
+
loop do
|
52
|
+
response = conn.get(url)
|
53
|
+
if response.status != 200
|
54
|
+
raise Error, 'Could not read package from galaxy API.'
|
55
|
+
else
|
56
|
+
json = JSON.parse(response.body)
|
57
|
+
package = json['results'].find do |r|
|
58
|
+
r['summary_fields']['owner']['username'] == username &&
|
59
|
+
r['name'] == name
|
60
|
+
end
|
61
|
+
return package if package
|
62
|
+
url = json['next']
|
63
|
+
break unless url
|
46
64
|
end
|
47
65
|
end
|
48
|
-
|
49
|
-
"https://github.com/#{package['github_user']}/#{package['github_repo']}"
|
50
66
|
end
|
51
|
-
|
52
67
|
end
|
53
|
-
|
54
68
|
end
|
55
69
|
end
|
56
70
|
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative "../../support/spec_helper"
|
2
|
+
require "librarian/ansible/cli"
|
3
|
+
|
4
|
+
module Librarian
|
5
|
+
module Ansible
|
6
|
+
describe Cli do
|
7
|
+
include Librarian::RSpec::Support::CliMacro
|
8
|
+
|
9
|
+
describe "init" do
|
10
|
+
before do
|
11
|
+
cli! "init"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create a file named Ansiblefile" do
|
15
|
+
pwd.should have_file "Ansiblefile"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "version" do
|
20
|
+
before do
|
21
|
+
cli! "version"
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should print the version" do
|
25
|
+
stdout.should == strip_heredoc(<<-STDOUT)
|
26
|
+
librarian-#{Librarian::VERSION}
|
27
|
+
librarian-ansible-#{Librarian::Ansible::VERSION}
|
28
|
+
STDOUT
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "install" do
|
33
|
+
|
34
|
+
context "a simple Ansiblefile with one role" do
|
35
|
+
let(:metadata) do
|
36
|
+
{ "name" => "apt",
|
37
|
+
"version" => "1.0.0" }
|
38
|
+
end
|
39
|
+
|
40
|
+
before do
|
41
|
+
write_yaml_file! "role-sources/apt/meta/main.yml", metadata
|
42
|
+
write_file! "Ansiblefile", strip_heredoc(<<-ANSIBLEFILE)
|
43
|
+
role 'apt',
|
44
|
+
:path => 'role-sources/apt'
|
45
|
+
ANSIBLEFILE
|
46
|
+
|
47
|
+
cli! "install"
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should write a lockfile" do
|
51
|
+
pwd.should have_file "Ansiblefile.lock"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should install the role" do
|
55
|
+
pwd.should have_yaml_file "librarian_roles/apt/meta/main.yml", metadata
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,363 @@
|
|
1
|
+
require 'librarian'
|
2
|
+
require 'librarian/helpers'
|
3
|
+
require 'librarian/error'
|
4
|
+
require 'librarian/action/resolve'
|
5
|
+
require 'librarian/action/install'
|
6
|
+
require 'librarian/action/update'
|
7
|
+
require 'librarian/ansible'
|
8
|
+
|
9
|
+
require 'support/project_path'
|
10
|
+
|
11
|
+
module Librarian
|
12
|
+
module Ansible
|
13
|
+
module Source
|
14
|
+
describe Git do
|
15
|
+
|
16
|
+
let(:project_path) { ::Support::ProjectPath.project_path }
|
17
|
+
let(:tmp_path) { project_path.join("tmp/spec/integration/ansible/source/git") }
|
18
|
+
after { tmp_path.rmtree if tmp_path && tmp_path.exist? }
|
19
|
+
|
20
|
+
let(:roles_path) { tmp_path.join("librarian_roles") }
|
21
|
+
|
22
|
+
# depends on repo_path being defined in each context
|
23
|
+
let(:env) { Environment.new(:project_path => repo_path) }
|
24
|
+
|
25
|
+
context "a single dependency with a git source" do
|
26
|
+
|
27
|
+
let(:sample_path) { tmp_path.join("sample") }
|
28
|
+
let(:sample_metadata) do
|
29
|
+
{ version: "0.6.5" }
|
30
|
+
end
|
31
|
+
|
32
|
+
let(:first_sample_path) { roles_path.join("first-sample") }
|
33
|
+
let(:first_sample_metadata) do
|
34
|
+
{ version: "3.2.1" }
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:second_sample_path) { roles_path.join("second-sample") }
|
38
|
+
let(:second_sample_metadata) do
|
39
|
+
{ version: "4.3.2" }
|
40
|
+
end
|
41
|
+
|
42
|
+
before do
|
43
|
+
sample_path.rmtree if sample_path.exist?
|
44
|
+
sample_path.join('meta').mkpath
|
45
|
+
sample_path.join("meta/main.yml").open("wb") { |f| f.write(YAML.dump(sample_metadata)) }
|
46
|
+
Dir.chdir(sample_path) do
|
47
|
+
`git init`
|
48
|
+
`git config user.name "Simba"`
|
49
|
+
`git config user.email "simba@savannah-pride.gov"`
|
50
|
+
`git add meta/main.yml`
|
51
|
+
`git commit -m "Initial commit."`
|
52
|
+
end
|
53
|
+
|
54
|
+
roles_path.rmtree if roles_path.exist?
|
55
|
+
roles_path.mkpath
|
56
|
+
first_sample_path.join('meta').mkpath
|
57
|
+
first_sample_path.join("meta/main.yml").open("wb") { |f| f.write(YAML.dump(first_sample_metadata)) }
|
58
|
+
second_sample_path.join('meta').mkpath
|
59
|
+
second_sample_path.join("meta/main.yml").open("wb") { |f| f.write(YAML.dump(second_sample_metadata)) }
|
60
|
+
Dir.chdir(roles_path) do
|
61
|
+
`git init`
|
62
|
+
`git config user.name "Simba"`
|
63
|
+
`git config user.email "simba@savannah-pride.gov"`
|
64
|
+
`git add .`
|
65
|
+
`git commit -m "Initial commit."`
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "resolving" do
|
70
|
+
let(:repo_path) { tmp_path.join("repo/resolve") }
|
71
|
+
before do
|
72
|
+
repo_path.rmtree if repo_path.exist?
|
73
|
+
repo_path.mkpath
|
74
|
+
repo_path.join("librarian_roles").mkpath
|
75
|
+
ansiblefile = Helpers.strip_heredoc(<<-ANSIBLEFILE)
|
76
|
+
#!/usr/bin/env ruby
|
77
|
+
role "sample", :git => #{sample_path.to_s.inspect}
|
78
|
+
ANSIBLEFILE
|
79
|
+
repo_path.join("Ansiblefile").open("wb") { |f| f.write(ansiblefile) }
|
80
|
+
end
|
81
|
+
|
82
|
+
context "the resolve" do
|
83
|
+
it "should not raise an exception" do
|
84
|
+
expect { Action::Resolve.new(env).run }.to_not raise_error
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context "the results" do
|
89
|
+
before { Action::Resolve.new(env).run }
|
90
|
+
|
91
|
+
it "should create the lockfile" do
|
92
|
+
repo_path.join("Ansiblefile.lock").should exist
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should not attempt to install the sample cookbok" do
|
96
|
+
repo_path.join("librarian_roles/sample").should_not exist
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "installing" do
|
102
|
+
let(:repo_path) { tmp_path.join("repo/install") }
|
103
|
+
before do
|
104
|
+
repo_path.rmtree if repo_path.exist?
|
105
|
+
repo_path.mkpath
|
106
|
+
repo_path.join(roles_path).mkpath
|
107
|
+
ansiblefile = Helpers.strip_heredoc(<<-ANSIBLEFILE)
|
108
|
+
#!/usr/bin/env ruby
|
109
|
+
role "sample", :git => #{sample_path.to_s.inspect}
|
110
|
+
ANSIBLEFILE
|
111
|
+
repo_path.join("Ansiblefile").open("wb") { |f| f.write(ansiblefile) }
|
112
|
+
|
113
|
+
Action::Resolve.new(env).run
|
114
|
+
end
|
115
|
+
|
116
|
+
context "the install" do
|
117
|
+
it "should not raise an exception" do
|
118
|
+
expect { Action::Install.new(env).run }.to_not raise_error
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
context "the results" do
|
123
|
+
before { Action::Install.new(env).run }
|
124
|
+
|
125
|
+
it "should create the lockfile" do
|
126
|
+
repo_path.join("Ansiblefile.lock").should exist
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should create the directory for the role" do
|
130
|
+
repo_path.join("librarian_roles/sample").should exist
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should copy the role files into the role directory" do
|
134
|
+
repo_path.join("librarian_roles/sample/meta/main.yml").should exist
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "resolving and and separately installing" do
|
140
|
+
let(:repo_path) { tmp_path.join("repo/resolve-install") }
|
141
|
+
before do
|
142
|
+
repo_path.rmtree if repo_path.exist?
|
143
|
+
repo_path.mkpath
|
144
|
+
repo_path.join("librarian_roles").mkpath
|
145
|
+
ansiblefile = Helpers.strip_heredoc(<<-ANSIBLEFILE)
|
146
|
+
#!/usr/bin/env ruby
|
147
|
+
role "sample", :git => #{sample_path.to_s.inspect}
|
148
|
+
ANSIBLEFILE
|
149
|
+
repo_path.join("Ansiblefile").open("wb") { |f| f.write(ansiblefile) }
|
150
|
+
|
151
|
+
Action::Resolve.new(env).run
|
152
|
+
repo_path.join("tmp").rmtree if repo_path.join("tmp").exist?
|
153
|
+
end
|
154
|
+
|
155
|
+
context "the install" do
|
156
|
+
it "should not raise an exception" do
|
157
|
+
expect { Action::Install.new(env).run }.to_not raise_error
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context "the results" do
|
162
|
+
before { Action::Install.new(env).run }
|
163
|
+
|
164
|
+
it "should create the directory for the role" do
|
165
|
+
repo_path.join("librarian_roles/sample").should exist
|
166
|
+
end
|
167
|
+
|
168
|
+
it "should copy the role files into the role directory" do
|
169
|
+
repo_path.join("librarian_roles/sample/meta/main.yml").should exist
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
end
|
175
|
+
|
176
|
+
context "with a path" do
|
177
|
+
|
178
|
+
let(:git_path) { tmp_path.join("big-git-repo") }
|
179
|
+
let(:sample_path) { git_path.join("buttercup") }
|
180
|
+
let(:sample_metadata) do
|
181
|
+
{ version: "0.6.5" }
|
182
|
+
end
|
183
|
+
|
184
|
+
before do
|
185
|
+
git_path.rmtree if git_path.exist?
|
186
|
+
git_path.mkpath
|
187
|
+
sample_path.join('meta').mkpath
|
188
|
+
sample_path.join("meta/main.yml").open("wb") { |f| f.write(YAML.dump(sample_metadata)) }
|
189
|
+
Dir.chdir(git_path) do
|
190
|
+
`git init`
|
191
|
+
`git config user.name "Simba"`
|
192
|
+
`git config user.email "simba@savannah-pride.gov"`
|
193
|
+
`git add .`
|
194
|
+
`git commit -m "Initial commit."`
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "if no path option is given" do
|
199
|
+
let(:repo_path) { tmp_path.join("repo/resolve") }
|
200
|
+
before do
|
201
|
+
repo_path.rmtree if repo_path.exist?
|
202
|
+
repo_path.mkpath
|
203
|
+
repo_path.join("librarian_roles").mkpath
|
204
|
+
ansiblefile = Helpers.strip_heredoc(<<-ANSIBLEFILE)
|
205
|
+
#!/usr/bin/env ruby
|
206
|
+
role "sample",
|
207
|
+
:git => #{git_path.to_s.inspect}
|
208
|
+
ANSIBLEFILE
|
209
|
+
repo_path.join("Ansiblefile").open("wb") { |f| f.write(ansiblefile) }
|
210
|
+
end
|
211
|
+
|
212
|
+
it "should not resolve" do
|
213
|
+
expect{ Action::Resolve.new(env).run }.to raise_error
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
context "if the path option is wrong" do
|
218
|
+
let(:repo_path) { tmp_path.join("repo/resolve") }
|
219
|
+
before do
|
220
|
+
repo_path.rmtree if repo_path.exist?
|
221
|
+
repo_path.mkpath
|
222
|
+
repo_path.join("librarian_roles").mkpath
|
223
|
+
ansiblefile = Helpers.strip_heredoc(<<-ANSIBLEFILE)
|
224
|
+
#!/usr/bin/env ruby
|
225
|
+
role "sample",
|
226
|
+
:git => #{git_path.to_s.inspect},
|
227
|
+
:path => "jelly"
|
228
|
+
ANSIBLEFILE
|
229
|
+
repo_path.join("Ansiblefile").open("wb") { |f| f.write(ansiblefile) }
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should not resolve" do
|
233
|
+
expect{ Action::Resolve.new(env).run }.to raise_error
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
context "if the path option is right" do
|
238
|
+
let(:repo_path) { tmp_path.join("repo/resolve") }
|
239
|
+
before do
|
240
|
+
repo_path.rmtree if repo_path.exist?
|
241
|
+
repo_path.mkpath
|
242
|
+
repo_path.join("librarian_roles").mkpath
|
243
|
+
ansiblefile = Helpers.strip_heredoc(<<-ANSIBLEFILE)
|
244
|
+
#!/usr/bin/env ruby
|
245
|
+
role "sample",
|
246
|
+
:git => #{git_path.to_s.inspect},
|
247
|
+
:path => "buttercup"
|
248
|
+
ANSIBLEFILE
|
249
|
+
repo_path.join("Ansiblefile").open("wb") { |f| f.write(ansiblefile) }
|
250
|
+
end
|
251
|
+
|
252
|
+
context "the resolve" do
|
253
|
+
it "should not raise an exception" do
|
254
|
+
expect { Action::Resolve.new(env).run }.to_not raise_error
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context "the results" do
|
259
|
+
before { Action::Resolve.new(env).run }
|
260
|
+
|
261
|
+
it "should create the lockfile" do
|
262
|
+
repo_path.join("Ansiblefile.lock").should exist
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
end
|
268
|
+
|
269
|
+
context "when upstream updates" do
|
270
|
+
let(:git_path) { tmp_path.join("upstream-updates-repo") }
|
271
|
+
let(:repo_path) { tmp_path.join("repo/resolve-with-upstream-updates") }
|
272
|
+
|
273
|
+
let(:sample_metadata) do
|
274
|
+
{ version: "0.6.5" }
|
275
|
+
end
|
276
|
+
|
277
|
+
before do
|
278
|
+
|
279
|
+
# set up the git repo as normal, but let's also set up a release-stable branch
|
280
|
+
# from which our Ansiblefile will only pull stable releases
|
281
|
+
git_path.rmtree if git_path.exist?
|
282
|
+
git_path.join('meta').mkpath
|
283
|
+
git_path.join("meta/main.yml").open("wb") { |f| f.write(YAML.dump(sample_metadata)) }
|
284
|
+
|
285
|
+
Dir.chdir(git_path) do
|
286
|
+
`git init`
|
287
|
+
`git config user.name "Simba"`
|
288
|
+
`git config user.email "simba@savannah-pride.gov"`
|
289
|
+
`git add meta/main.yml`
|
290
|
+
`git commit -m "Initial Commit."`
|
291
|
+
`git checkout -b some-branch --quiet`
|
292
|
+
`echo 'hi' > some-file`
|
293
|
+
`git add some-file`
|
294
|
+
`git commit -m 'Some File.'`
|
295
|
+
`git checkout master --quiet`
|
296
|
+
end
|
297
|
+
|
298
|
+
# set up the ansible repo as normal, except the Ansiblefile points to the release-stable
|
299
|
+
# branch - we expect when the upstream copy of that branch is changed, then we can
|
300
|
+
# fetch & merge those changes when we update
|
301
|
+
repo_path.rmtree if repo_path.exist?
|
302
|
+
repo_path.mkpath
|
303
|
+
repo_path.join("librarian_roles").mkpath
|
304
|
+
ansiblefile = Helpers.strip_heredoc(<<-ANSIBLEFILE)
|
305
|
+
role "sample",
|
306
|
+
:git => #{git_path.to_s.inspect},
|
307
|
+
:ref => "some-branch"
|
308
|
+
ANSIBLEFILE
|
309
|
+
repo_path.join("Ansiblefile").open("wb") { |f| f.write(ansiblefile) }
|
310
|
+
Action::Resolve.new(env).run
|
311
|
+
|
312
|
+
# change the upstream copy of that branch: we expect to be able to pull the latest
|
313
|
+
# when we re-resolve
|
314
|
+
Dir.chdir(git_path) do
|
315
|
+
`git checkout some-branch --quiet`
|
316
|
+
`echo 'ho' > some-other-file`
|
317
|
+
`git add some-other-file`
|
318
|
+
`git commit -m 'Some Other File.'`
|
319
|
+
`git checkout master --quiet`
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
let(:metadata_file) { repo_path.join("librarian_roles/sample/meta/main.yml") }
|
324
|
+
let(:old_code_file) { repo_path.join("librarian_roles/sample/some-file") }
|
325
|
+
let(:new_code_file) { repo_path.join("librarian_roles/sample/some-other-file") }
|
326
|
+
|
327
|
+
context "when updating not a role from that source" do
|
328
|
+
before do
|
329
|
+
Action::Update.new(env).run
|
330
|
+
end
|
331
|
+
|
332
|
+
it "should pull the tip from upstream" do
|
333
|
+
Action::Install.new(env).run
|
334
|
+
|
335
|
+
metadata_file.should exist #sanity
|
336
|
+
old_code_file.should exist #sanity
|
337
|
+
|
338
|
+
new_code_file.should_not exist # the assertion
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
context "when updating a role from that source" do
|
343
|
+
before do
|
344
|
+
Action::Update.new(env, :names => %w(sample)).run
|
345
|
+
end
|
346
|
+
|
347
|
+
it "should pull the tip from upstream" do
|
348
|
+
pending('debug "should pull the tip from upstream"')
|
349
|
+
|
350
|
+
Action::Install.new(env).run
|
351
|
+
|
352
|
+
metadata_file.should exist #sanity
|
353
|
+
old_code_file.should exist #sanity
|
354
|
+
|
355
|
+
new_code_file.should exist # the assertion
|
356
|
+
end
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
end
|
361
|
+
end
|
362
|
+
end
|
363
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Support
|
2
|
+
module ProjectPath
|
3
|
+
|
4
|
+
project_path = Pathname.new(__FILE__).expand_path
|
5
|
+
project_path = project_path.dirname until project_path.join("Rakefile").exist?
|
6
|
+
project_path
|
7
|
+
|
8
|
+
PROJECT_PATH = project_path
|
9
|
+
|
10
|
+
def project_path
|
11
|
+
PROJECT_PATH
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def project_path
|
16
|
+
PROJECT_PATH
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.included(base)
|
21
|
+
base.extend ClassMethods
|
22
|
+
end
|
23
|
+
|
24
|
+
extend self
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "librarian/rspec/support/cli_macro"
|
2
|
+
|
3
|
+
class FileMatcher < Librarian::RSpec::Support::CliMacro::FileMatcher
|
4
|
+
def actual_content
|
5
|
+
@actual_content ||= begin
|
6
|
+
content = full_path.read
|
7
|
+
content = JSON.parse(content) if type == :json
|
8
|
+
content = YAML.load(content) if type == :yaml
|
9
|
+
content
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def failure_message
|
14
|
+
if full_path.file?
|
15
|
+
"file content does not match"
|
16
|
+
else
|
17
|
+
"no file matches path #{rel_path}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def write_yaml_file!(path, content)
|
23
|
+
write_file! path, YAML.dump(content)
|
24
|
+
end
|
25
|
+
|
26
|
+
def have_yaml_file(rel_path, content)
|
27
|
+
FileMatcher.new(rel_path, content, :type => :yaml)
|
28
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: librarian-ansible
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Benjamin Coe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: librarian
|
@@ -75,6 +75,7 @@ extensions: []
|
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
77
|
- .gitignore
|
78
|
+
- .travis.yml
|
78
79
|
- Gemfile
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
@@ -99,6 +100,10 @@ files:
|
|
99
100
|
- lib/librarian/ansible/templates/Ansiblefile
|
100
101
|
- lib/librarian/ansible/version.rb
|
101
102
|
- librarian-ansible.gemspec
|
103
|
+
- spec/functional/ansible/cli_spec.rb
|
104
|
+
- spec/integration/ansible/source/git_spec.rb
|
105
|
+
- spec/support/project_path.rb
|
106
|
+
- spec/support/spec_helper.rb
|
102
107
|
homepage: ''
|
103
108
|
licenses:
|
104
109
|
- MIT
|
@@ -123,4 +128,8 @@ rubygems_version: 2.2.2
|
|
123
128
|
signing_key:
|
124
129
|
specification_version: 4
|
125
130
|
summary: A Bundler for your Ansible roles.
|
126
|
-
test_files:
|
131
|
+
test_files:
|
132
|
+
- spec/functional/ansible/cli_spec.rb
|
133
|
+
- spec/integration/ansible/source/git_spec.rb
|
134
|
+
- spec/support/project_path.rb
|
135
|
+
- spec/support/spec_helper.rb
|