orats 0.7.2 → 0.7.3
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/README.md +58 -3
- data/lib/orats/cli.rb +21 -0
- data/lib/orats/commands/project/rails.rb +7 -5
- data/lib/orats/commands/role.rb +70 -0
- data/lib/orats/templates/includes/common/.gitignore +6 -0
- data/lib/orats/templates/includes/inventory/group_vars/all.yml +21 -0
- data/lib/orats/templates/includes/playbook/Galaxyfile +4 -2
- data/lib/orats/templates/includes/playbook/common.yml +23 -0
- data/lib/orats/templates/includes/playbook/site.yml +7 -25
- data/lib/orats/templates/includes/role/.travis.yml +19 -0
- data/lib/orats/templates/includes/role/README.md +62 -0
- data/lib/orats/templates/includes/role/meta/main.yml +123 -0
- data/lib/orats/templates/includes/role/tests/inventory +1 -0
- data/lib/orats/templates/includes/role/tests/main.yml +7 -0
- data/lib/orats/templates/playbook.rb +19 -9
- data/lib/orats/templates/role.rb +144 -0
- data/lib/orats/version.rb +1 -1
- data/test/integration/cli_test.rb +31 -0
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93556f428c47b927511dad2d9bc4581f08512abe
|
4
|
+
data.tar.gz: f20bb7f697ce51209756d7ab10274f5df982847d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7c17135f4b66475105a0226cca3c8431155e6e776ed517655d3dccb4f71bd9b7f27099624d51352009eaf23e6aa24b032b28c1a620f34c9e9db59ce892a69aa7
|
7
|
+
data.tar.gz: 79546ec90a891606628f65699c0d5cb6d82f638252a095fcd801bb5c7578f267fcaee1830ab0743dc879a0d9c292bcb1699287870fb34bf57b1ff2498624882f
|
data/README.md
CHANGED
@@ -25,6 +25,8 @@ Gems will also be updated once they are proven to work on the target rails/ruby
|
|
25
25
|
- [Ansible roles](#ansible-roles-used)
|
26
26
|
- [FAQ](#playbook-faq)
|
27
27
|
- [What is the Galaxyfile?](#what-is-the-galaxyfile)
|
28
|
+
- [Role](#role)
|
29
|
+
- [Try it](#try-the-role-command)
|
28
30
|
- [Diff](#diff)
|
29
31
|
- [Try it](#try-the-diff-command)
|
30
32
|
- [Templates](#templates)
|
@@ -105,6 +107,13 @@ Here is an overview of the available commands. You can find out more information
|
|
105
107
|
- Template:
|
106
108
|
- Optionally takes: `--custom []`
|
107
109
|
|
110
|
+
- **Create a new ansible role**:
|
111
|
+
- `orats role <TARGET_PATH>`
|
112
|
+
- Configuration:
|
113
|
+
- Optionally takes: `--repo-name []`
|
114
|
+
- Template:
|
115
|
+
- Optionally takes: `--custom []`
|
116
|
+
|
108
117
|
- **Delete a directory and optionally all data associated to it**:
|
109
118
|
- `orats nuke <TARGET_PATH>`
|
110
119
|
- Optionally takes: `--skip-data [false]`
|
@@ -181,8 +190,8 @@ Everything is broken up into ansible roles so you can quickly scale out horizont
|
|
181
190
|
- **Security**:
|
182
191
|
- Logging into the server is only possible with an ssh key
|
183
192
|
- Root login is disable
|
184
|
-
- fail2ban is setup
|
185
|
-
-
|
193
|
+
- fail2ban is setup and configurable
|
194
|
+
- ferm (firewall) is setup to block any ports not exposed by you
|
186
195
|
- All stack specific processes are running with less privileges than root
|
187
196
|
- **User**:
|
188
197
|
- A single deploy user is created
|
@@ -202,8 +211,10 @@ Everything is broken up into ansible roles so you can quickly scale out horizont
|
|
202
211
|
#### Ansible roles used
|
203
212
|
|
204
213
|
- `nickjj.locale` https://github.com/nickjj/ansible-locale [](http://travis-ci.org/nickjj/ansible-locale)
|
214
|
+
- `nickjj.sshd` https://github.com/nickjj/ansible-sshd [](http://travis-ci.org/nickjj/ansible-sshd)
|
215
|
+
- `nickjj.ferm` https://github.com/nickjj/ansible-ferm [](http://travis-ci.org/nickjj/ansible-ferm)
|
216
|
+
- `nickjj.fail2ban` https://github.com/nickjj/ansible-fail2ban [](http://travis-ci.org/nickjj/ansible-fail2ban)
|
205
217
|
- `nickjj.user` https://github.com/nickjj/ansible-user [](http://travis-ci.org/nickjj/ansible-user)
|
206
|
-
- `nickjj.security` https://github.com/nickjj/ansible-security
|
207
218
|
- `nickjj.postgres` https://github.com/nickjj/ansible-postgres [](http://travis-ci.org/nickjj/ansible-postgres)
|
208
219
|
- `nickjj.ruby` https://github.com/nickjj/ansible-ruby [](http://travis-ci.org/nickjj/ansible-ruby)
|
209
220
|
- `nickjj.rails` https://github.com/nickjj/ansible-rails [](http://travis-ci.org/nickjj/ansible-rails)
|
@@ -241,6 +252,50 @@ Since the roles are self contained in the playbook this allows you to have
|
|
241
252
|
multiple playbooks with certain role versions in case you have older orats
|
242
253
|
projects which require older role versions.
|
243
254
|
|
255
|
+
### Role
|
256
|
+
|
257
|
+
The role command generates an ansible role with a few opinions. The
|
258
|
+
`ansible-galaxy` command that ships with ansible already comes with an `init`
|
259
|
+
function but the formatting of the files wasn't to my liking.
|
260
|
+
|
261
|
+
I also wanted it to add in tests using travis-ci and setup a basic
|
262
|
+
idempotence test for all new roles.
|
263
|
+
|
264
|
+
#### Changes vs ansible-galaxy init
|
265
|
+
|
266
|
+
All of the changes have git commits to go with them. After generating a role you
|
267
|
+
can type `git reflog` to get a list of changes.
|
268
|
+
|
269
|
+
- **Core changes**:
|
270
|
+
- Add travis-ci tests
|
271
|
+
- Remove the `vars` folder
|
272
|
+
- Add `LICENSE` (MIT)
|
273
|
+
- Add `.gitignore`
|
274
|
+
- **meta/main.yml**:
|
275
|
+
- Automatically fill in the author name based on your git name
|
276
|
+
- **README.md**:
|
277
|
+
- Add a travis badge
|
278
|
+
- Add a section to link back to your role on the official ansible galaxy
|
279
|
+
- Automatically fill in your repo name, role name and name where necessary
|
280
|
+
- Add instructions for using the role in an example playbook
|
281
|
+
- Add a todo list for you to make the role your own
|
282
|
+
|
283
|
+
#### Try the role command
|
284
|
+
|
285
|
+
##### Basic
|
286
|
+
|
287
|
+
`orats role your_github_user_name.myrole`
|
288
|
+
|
289
|
+
##### Custom repo name
|
290
|
+
|
291
|
+
`orats role your_github_user_name.mynewrole --repo-name ansible-mynewrole`
|
292
|
+
|
293
|
+
The custom repo name is probably what you'll want to use all the time if you
|
294
|
+
plan to make your roles open source. For example my roles are named things like `nickjj.postgres` and `nickjj.rails`. However my repos are named `ansible-postgres` and `ansible-rails`.
|
295
|
+
|
296
|
+
When you submit your role to the galaxy you would use `rails` as the
|
297
|
+
optional name for your role.
|
298
|
+
|
244
299
|
### Diff
|
245
300
|
|
246
301
|
The goal of the diff command is to compare your orats generated files with
|
data/lib/orats/cli.rb
CHANGED
@@ -2,6 +2,7 @@ require 'thor'
|
|
2
2
|
require 'orats/commands/project/exec'
|
3
3
|
require 'orats/commands/inventory'
|
4
4
|
require 'orats/commands/playbook'
|
5
|
+
require 'orats/commands/role'
|
5
6
|
require 'orats/commands/nuke'
|
6
7
|
require 'orats/commands/diff/exec'
|
7
8
|
|
@@ -79,6 +80,26 @@ module Orats
|
|
79
80
|
Commands::Playbook.new(target_path, options).init
|
80
81
|
end
|
81
82
|
|
83
|
+
option :repo_name, default: '', aliases: '-r'
|
84
|
+
option :custom, default: '', aliases: '-c'
|
85
|
+
desc 'role TARGET_PATH [options]', ''
|
86
|
+
long_desc <<-D
|
87
|
+
`orats role target_path` will create an ansible role suitable for the galaxy.
|
88
|
+
|
89
|
+
Configuration:
|
90
|
+
|
91
|
+
`--repo-name` if your github repo name is different than the full role name
|
92
|
+
|
93
|
+
Template features:
|
94
|
+
|
95
|
+
`--custom` will let you supply a custom template, a url or file is ok but urls
|
96
|
+
must start with http or https []
|
97
|
+
D
|
98
|
+
|
99
|
+
def role(target_path)
|
100
|
+
Commands::Role.new(target_path, options).init
|
101
|
+
end
|
102
|
+
|
82
103
|
option :skip_data, type: :boolean, default: false, aliases: '-D'
|
83
104
|
option :redis_password, default: '', aliases: '-d'
|
84
105
|
desc 'nuke TARGET_PATH [options]', ''
|
@@ -2,9 +2,9 @@ module Orats
|
|
2
2
|
module Commands
|
3
3
|
module Project
|
4
4
|
module Rails
|
5
|
-
def check_exit_conditions
|
5
|
+
def check_exit_conditions(check_running_processes: true)
|
6
6
|
exit_if_process :not_found, 'rails', 'git'
|
7
|
-
exit_if_process :not_running, 'postgres', 'redis'
|
7
|
+
exit_if_process :not_running, 'postgres', 'redis' if check_running_processes
|
8
8
|
exit_if_path_exists
|
9
9
|
exit_if_invalid_template
|
10
10
|
end
|
@@ -132,12 +132,14 @@ module Orats
|
|
132
132
|
private
|
133
133
|
|
134
134
|
def exit_if_invalid_template
|
135
|
-
|
135
|
+
template = @options[:template] || ''
|
136
|
+
|
137
|
+
if template.length > 0
|
136
138
|
log_task 'Check if template exists'
|
137
139
|
|
138
|
-
unless template_exist?(
|
140
|
+
unless template_exist?(template)
|
139
141
|
log_error 'error', 'Cannot find template', 'message',
|
140
|
-
"'#{
|
142
|
+
"'#{template}' is not a valid template name",
|
141
143
|
true do
|
142
144
|
log_status_bottom 'tip',
|
143
145
|
'run `orats templates` to get a list of valid templates',
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'orats/commands/common'
|
2
|
+
require 'orats/commands/project/rails'
|
3
|
+
|
4
|
+
module Orats
|
5
|
+
module Commands
|
6
|
+
class Role < Common
|
7
|
+
include Project::Rails
|
8
|
+
|
9
|
+
def initialize(target_path = '', options = {})
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
def init
|
14
|
+
check_exit_conditions check_running_processes: false
|
15
|
+
exit_if_invalid_role_name
|
16
|
+
|
17
|
+
rails_template 'role'
|
18
|
+
custom_rails_template unless @options[:custom].empty?
|
19
|
+
|
20
|
+
repo_name = @options[:repo_name].empty? ? base_file_name :
|
21
|
+
@options[:repo_name]
|
22
|
+
|
23
|
+
log_task 'Update place holder repo name'
|
24
|
+
gsub_file "#{@target_path}/README.md", 'repo_name',
|
25
|
+
repo_name
|
26
|
+
gsub_file "#{@target_path}/tests/main.yml", 'repo_name',
|
27
|
+
repo_name
|
28
|
+
git_commit 'Update place holder repo name'
|
29
|
+
|
30
|
+
log_success
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def base_file_name
|
36
|
+
File.basename(@target_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def exit_if_invalid_role_name
|
40
|
+
log_task 'Check if role name is valid'
|
41
|
+
|
42
|
+
unless base_file_name.count('.') == 1
|
43
|
+
log_error 'error', 'Invalid role name', 'message',
|
44
|
+
"'#{base_file_name}' is invalid, it must contain 1 period",
|
45
|
+
true do
|
46
|
+
log_status_bottom 'tip',
|
47
|
+
'Your role name should be github_user.role_name',
|
48
|
+
:white
|
49
|
+
end
|
50
|
+
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def log_success
|
56
|
+
log_status_top 'success', 'Everything has been setup successfully',
|
57
|
+
:cyan
|
58
|
+
puts
|
59
|
+
log_status_bottom 'question', 'What should you do next?', :yellow, true
|
60
|
+
log_status_bottom 'answer', 'Check the readme in the role',
|
61
|
+
:white
|
62
|
+
|
63
|
+
log_status_bottom 'question', 'Are you new to ansible?', :yellow, true
|
64
|
+
log_status_bottom 'answer',
|
65
|
+
'http://docs.ansible.com/intro_getting_started.html',
|
66
|
+
:white
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -30,6 +30,27 @@ ansible_ssh_user: deploy
|
|
30
30
|
# https://github.com/nickjj/ansible-locale/#role-variables
|
31
31
|
# -----------------------------------------------------------------------------
|
32
32
|
|
33
|
+
# -----------------------------------------------------------------------------
|
34
|
+
# sshd
|
35
|
+
# -----------------------------------------------------------------------------
|
36
|
+
# default values you can overwrite with documentation:
|
37
|
+
# https://github.com/nickjj/ansible-sshd/#role-variables
|
38
|
+
# -----------------------------------------------------------------------------
|
39
|
+
|
40
|
+
# -----------------------------------------------------------------------------
|
41
|
+
# ferm
|
42
|
+
# -----------------------------------------------------------------------------
|
43
|
+
# default values you can overwrite with documentation:
|
44
|
+
# https://github.com/nickjj/ansible-ferm/#role-variables
|
45
|
+
# -----------------------------------------------------------------------------
|
46
|
+
|
47
|
+
# -----------------------------------------------------------------------------
|
48
|
+
# fail2ban
|
49
|
+
# -----------------------------------------------------------------------------
|
50
|
+
# default values you can overwrite with documentation:
|
51
|
+
# https://github.com/nickjj/ansible-fail2ban/#role-variables
|
52
|
+
# -----------------------------------------------------------------------------
|
53
|
+
|
33
54
|
# -----------------------------------------------------------------------------
|
34
55
|
# user
|
35
56
|
# -----------------------------------------------------------------------------
|
@@ -1,8 +1,10 @@
|
|
1
1
|
nickjj.locale,v0.1.1
|
2
|
+
nickjj.sshd,v0.1.2
|
3
|
+
nickjj.ferm,v0.1.1
|
4
|
+
nickjj.fail2ban,v0.1.2
|
2
5
|
nickjj.user,v0.1.0
|
3
|
-
nickjj.security,v0.1.2
|
4
6
|
nickjj.postgres,v0.1.3
|
5
|
-
nickjj.ruby,v0.1.
|
7
|
+
nickjj.ruby,v0.1.9
|
6
8
|
nickjj.nodejs,v0.1.1
|
7
9
|
nickjj.nginx,v0.1.4
|
8
10
|
nickjj.rails,v0.2.2
|
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
- name: ensure all servers are commonly configured without sudo
|
3
|
+
hosts: all:!localhost
|
4
|
+
sudo: false
|
5
|
+
|
6
|
+
tasks:
|
7
|
+
- name: ensure IP address of the ansible controller is set
|
8
|
+
set_fact:
|
9
|
+
ansible_controller: '{{ ansible_env.SSH_CLIENT.split(" ") | first }}/32'
|
10
|
+
when: (ansible_controller is undefined and ansible_connection != "local")
|
11
|
+
tags: [common, ferm]
|
12
|
+
|
13
|
+
|
14
|
+
- name: ensure all servers are commonly configured with sudo
|
15
|
+
hosts: all
|
16
|
+
sudo: true
|
17
|
+
|
18
|
+
roles:
|
19
|
+
- { role: nickjj.locale, tags: [common, locale] }
|
20
|
+
- { role: nickjj.sshd, tags: [common, sshd] }
|
21
|
+
- { role: nickjj.ferm, tags: [common, ferm] }
|
22
|
+
- { role: nickjj.fail2ban, tags: [common, fail2ban] }
|
23
|
+
- { role: nickjj.user, tags: [common, user] }
|
@@ -1,23 +1,11 @@
|
|
1
1
|
---
|
2
|
-
-
|
3
|
-
hosts: all
|
4
|
-
sudo: true
|
5
|
-
|
6
|
-
roles:
|
7
|
-
- { role: nickjj.locale, tags: [common, locale] }
|
8
|
-
- { role: nickjj.user, tags: [common, user] }
|
2
|
+
- include: common.yml
|
9
3
|
|
10
4
|
- name: ensure database servers are configured
|
11
5
|
hosts: database
|
12
6
|
sudo: true
|
13
7
|
|
14
8
|
roles:
|
15
|
-
- role: nickjj.security
|
16
|
-
tags: [database, security]
|
17
|
-
security_ufw_ports:
|
18
|
-
- rule: deny
|
19
|
-
port: 80
|
20
|
-
proto: tcp
|
21
9
|
- { role: nickjj.postgres, tags: [database, postgres] }
|
22
10
|
|
23
11
|
- name: ensure cache servers are configured
|
@@ -25,12 +13,6 @@
|
|
25
13
|
sudo: true
|
26
14
|
|
27
15
|
roles:
|
28
|
-
- role: nickjj.security
|
29
|
-
tags: [cache, security]
|
30
|
-
security_ufw_ports:
|
31
|
-
- rule: deny
|
32
|
-
port: 80
|
33
|
-
proto: tcp
|
34
16
|
- { role: DavidWittman.redis, tags: [cache, redis] }
|
35
17
|
|
36
18
|
- name: ensure app servers are configured
|
@@ -38,12 +20,12 @@
|
|
38
20
|
sudo: true
|
39
21
|
|
40
22
|
roles:
|
41
|
-
- role: nickjj.
|
42
|
-
tags: [app,
|
43
|
-
|
44
|
-
-
|
45
|
-
|
46
|
-
|
23
|
+
- role: nickjj.ferm
|
24
|
+
tags: [app, ferm]
|
25
|
+
ferm_input_list:
|
26
|
+
- type: "dport_accept"
|
27
|
+
dport: ["http", "https"]
|
28
|
+
|
47
29
|
- { role: nickjj.ruby, tags: [app, ruby] }
|
48
30
|
- { role: nickjj.nodejs, tags: [app, nodejs] }
|
49
31
|
- { role: nickjj.nginx, tags: [app, nginx] }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
---
|
2
|
+
language: "python"
|
3
|
+
python: "2.7"
|
4
|
+
|
5
|
+
env:
|
6
|
+
- SITE_AND_INVENTORY="tests/main.yml -i tests/inventory"
|
7
|
+
|
8
|
+
install:
|
9
|
+
- "pip install ansible==1.6.2"
|
10
|
+
- "printf '[defaults]\nroles_path = ../' > ansible.cfg"
|
11
|
+
|
12
|
+
script:
|
13
|
+
- "ansible-playbook $SITE_AND_INVENTORY --syntax-check"
|
14
|
+
- "ansible-playbook $SITE_AND_INVENTORY --connection=local -vvvv"
|
15
|
+
- >
|
16
|
+
ansible-playbook $SITE_AND_INVENTORY --connection=local
|
17
|
+
| grep -q 'changed=0.*failed=0'
|
18
|
+
&& (echo 'Idempotence test: pass' && exit 0)
|
19
|
+
|| (echo 'Idempotence test: fail' && exit 1)
|
@@ -0,0 +1,62 @@
|
|
1
|
+
## What is repo_name? [](http://travis-ci.org/github_user/repo_name)
|
2
|
+
|
3
|
+
It is an [ansible](http://www.ansible.com/home) role to <enter what the role is about>.
|
4
|
+
|
5
|
+
### What problem does it solve and why is it useful?
|
6
|
+
|
7
|
+
Thanks for generating a role with orats. Here's your todo list:
|
8
|
+
|
9
|
+
- Change `meta/main.yml` to your liking
|
10
|
+
- Create your awesome role
|
11
|
+
- Fill out this readme properly
|
12
|
+
- Sign up for [travis-ci.org](http://travis-ci.org) (it is free for public repos)
|
13
|
+
- Review `.travis.yml` and write reasonable tests
|
14
|
+
- Push your role to github and tag it with a version number
|
15
|
+
- Publish your role on the [ansible galaxy](https://galaxy.ansible.com) if it's not private
|
16
|
+
- Replace the `role_id` with your id in the `Ansible galaxy` section of this readme
|
17
|
+
|
18
|
+
## Role variables
|
19
|
+
|
20
|
+
Below is a list of default values along with a description of what they do.
|
21
|
+
|
22
|
+
```
|
23
|
+
# Add your default role variables here.
|
24
|
+
```
|
25
|
+
|
26
|
+
## Example playbook
|
27
|
+
|
28
|
+
For the sake of this example let's assume you have a group called **foo** and you have a typical `site.yml` file.
|
29
|
+
|
30
|
+
To use this role edit your `site.yml` file to look something like this:
|
31
|
+
|
32
|
+
```
|
33
|
+
---
|
34
|
+
- name: ensure foo servers are configured
|
35
|
+
- hosts: foo
|
36
|
+
|
37
|
+
roles:
|
38
|
+
- { role: github_user.role_name, tags: role_name }
|
39
|
+
```
|
40
|
+
|
41
|
+
Let's say you want to edit a few values, you can do this by opening or creating `group_vars/foo.yml` which is located relative to your `inventory` directory and then making it look something like this:
|
42
|
+
|
43
|
+
```
|
44
|
+
---
|
45
|
+
# Overwrite the defaults here.
|
46
|
+
```
|
47
|
+
|
48
|
+
## Installation
|
49
|
+
|
50
|
+
`$ ansible-galaxy install github_user.role_name`
|
51
|
+
|
52
|
+
## Requirements
|
53
|
+
|
54
|
+
Tested on <enter your OS of choice>.
|
55
|
+
|
56
|
+
## Ansible galaxy
|
57
|
+
|
58
|
+
You can find it on the official [ansible galaxy](https://galaxy.ansible.com/list#/roles/role_id) if you want to rate it.
|
59
|
+
|
60
|
+
## License
|
61
|
+
|
62
|
+
MIT
|
@@ -0,0 +1,123 @@
|
|
1
|
+
---
|
2
|
+
galaxy_info:
|
3
|
+
author: author_name
|
4
|
+
description: Enter a short description about this role.
|
5
|
+
company: Your company (optional).
|
6
|
+
# Some suggested licenses:
|
7
|
+
# - BSD (default)
|
8
|
+
# - MIT
|
9
|
+
# - GPLv2
|
10
|
+
# - GPLv3
|
11
|
+
# - Apache
|
12
|
+
# - CC-BY
|
13
|
+
license: license MIT
|
14
|
+
min_ansible_version: 1.6
|
15
|
+
#
|
16
|
+
# Below are all platforms currently available. Just uncomment
|
17
|
+
# the ones that apply to your role. If you don't see your
|
18
|
+
# platform on this list, let us know and we'll get it added!
|
19
|
+
#
|
20
|
+
#platforms:
|
21
|
+
#- name: EL
|
22
|
+
# versions:
|
23
|
+
# - all
|
24
|
+
# - 5
|
25
|
+
# - 6
|
26
|
+
# - 7
|
27
|
+
#- name: GenericUNIX
|
28
|
+
# versions:
|
29
|
+
# - all
|
30
|
+
# - any
|
31
|
+
#- name: Fedora
|
32
|
+
# versions:
|
33
|
+
# - all
|
34
|
+
# - 16
|
35
|
+
# - 17
|
36
|
+
# - 18
|
37
|
+
# - 19
|
38
|
+
# - 20
|
39
|
+
#- name: opensuse
|
40
|
+
# versions:
|
41
|
+
# - all
|
42
|
+
# - 12.1
|
43
|
+
# - 12.2
|
44
|
+
# - 12.3
|
45
|
+
# - 13.1
|
46
|
+
# - 13.2
|
47
|
+
#- name: Amazon
|
48
|
+
# versions:
|
49
|
+
# - all
|
50
|
+
# - 2013.03
|
51
|
+
# - 2013.09
|
52
|
+
#- name: GenericBSD
|
53
|
+
# versions:
|
54
|
+
# - all
|
55
|
+
# - any
|
56
|
+
#- name: FreeBSD
|
57
|
+
# versions:
|
58
|
+
# - all
|
59
|
+
# - 8.0
|
60
|
+
# - 8.1
|
61
|
+
# - 8.2
|
62
|
+
# - 8.3
|
63
|
+
# - 8.4
|
64
|
+
# - 9.0
|
65
|
+
# - 9.1
|
66
|
+
# - 9.1
|
67
|
+
# - 9.2
|
68
|
+
#- name: Ubuntu
|
69
|
+
# versions:
|
70
|
+
# - all
|
71
|
+
# - lucid
|
72
|
+
# - maverick
|
73
|
+
# - natty
|
74
|
+
# - oneiric
|
75
|
+
# - precise
|
76
|
+
# - quantal
|
77
|
+
# - raring
|
78
|
+
# - saucy
|
79
|
+
# - trusty
|
80
|
+
#- name: SLES
|
81
|
+
# versions:
|
82
|
+
# - all
|
83
|
+
# - 10SP3
|
84
|
+
# - 10SP4
|
85
|
+
# - 11
|
86
|
+
# - 11SP1
|
87
|
+
# - 11SP2
|
88
|
+
# - 11SP3
|
89
|
+
#- name: GenericLinux
|
90
|
+
# versions:
|
91
|
+
# - all
|
92
|
+
# - any
|
93
|
+
#- name: Debian
|
94
|
+
# versions:
|
95
|
+
# - all
|
96
|
+
# - etch
|
97
|
+
# - lenny
|
98
|
+
# - squeeze
|
99
|
+
# - wheezy
|
100
|
+
#
|
101
|
+
# Below are all categories currently available. Just as with
|
102
|
+
# the platforms above, uncomment those that apply to your role.
|
103
|
+
#
|
104
|
+
#categories:
|
105
|
+
#- cloud
|
106
|
+
#- cloud:ec2
|
107
|
+
#- cloud:gce
|
108
|
+
#- cloud:rax
|
109
|
+
#- clustering
|
110
|
+
#- database
|
111
|
+
#- database:nosql
|
112
|
+
#- database:sql
|
113
|
+
#- development
|
114
|
+
#- monitoring
|
115
|
+
#- networking
|
116
|
+
#- packaging
|
117
|
+
#- system
|
118
|
+
#- web
|
119
|
+
dependencies: []
|
120
|
+
# List your role dependencies here, one per line. Only
|
121
|
+
# dependencies available via galaxy should be listed here.
|
122
|
+
# Be sure to remove the '[]' above if you add dependencies
|
123
|
+
# to this list.
|
@@ -0,0 +1 @@
|
|
1
|
+
localhost
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'securerandom'
|
2
|
-
|
3
1
|
# =============================================================================
|
4
2
|
# template for generating an orats ansible playbook for ansible 1.6.x
|
5
3
|
# =============================================================================
|
@@ -9,10 +7,6 @@ require 'securerandom'
|
|
9
7
|
# -----------------------------------------------------------------------------
|
10
8
|
# private functions
|
11
9
|
# -----------------------------------------------------------------------------
|
12
|
-
def generate_token
|
13
|
-
SecureRandom.hex(64)
|
14
|
-
end
|
15
|
-
|
16
10
|
def method_to_sentence(method)
|
17
11
|
method.tr!('_', ' ')
|
18
12
|
method[0] = method[0].upcase
|
@@ -65,6 +59,13 @@ def add_playbook_directory
|
|
65
59
|
git_commit 'Initial commit'
|
66
60
|
end
|
67
61
|
|
62
|
+
def add_gitignore
|
63
|
+
log_task __method__
|
64
|
+
|
65
|
+
copy_from_local_gem '../common/.gitignore', '.gitignore'
|
66
|
+
git_commit 'Add .gitignore'
|
67
|
+
end
|
68
|
+
|
68
69
|
def add_license
|
69
70
|
log_task __method__
|
70
71
|
|
@@ -78,11 +79,18 @@ def add_license
|
|
78
79
|
git_commit 'Add MIT license'
|
79
80
|
end
|
80
81
|
|
81
|
-
def
|
82
|
+
def add_common_plays
|
83
|
+
log_task __method__
|
84
|
+
|
85
|
+
copy_from_local_gem 'common.yml'
|
86
|
+
git_commit 'Add common playsk'
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_site_plays
|
82
90
|
log_task __method__
|
83
91
|
|
84
92
|
copy_from_local_gem 'site.yml'
|
85
|
-
git_commit 'Add the
|
93
|
+
git_commit 'Add the site plays'
|
86
94
|
end
|
87
95
|
|
88
96
|
def add_galaxyfile
|
@@ -103,7 +111,9 @@ end
|
|
103
111
|
|
104
112
|
delete_generated_rails_code
|
105
113
|
add_playbook_directory
|
114
|
+
add_gitignore
|
106
115
|
add_license
|
107
|
-
|
116
|
+
add_common_plays
|
117
|
+
add_site_plays
|
108
118
|
add_galaxyfile
|
109
119
|
remove_unused_files_from_git
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# =============================================================================
|
2
|
+
# template for generating an orats ansible role for ansible 1.6.x
|
3
|
+
# =============================================================================
|
4
|
+
# view the task list at the bottom of the file
|
5
|
+
# -----------------------------------------------------------------------------
|
6
|
+
|
7
|
+
# -----------------------------------------------------------------------------
|
8
|
+
# private functions
|
9
|
+
# -----------------------------------------------------------------------------
|
10
|
+
def method_to_sentence(method)
|
11
|
+
method.tr!('_', ' ')
|
12
|
+
method[0] = method[0].upcase
|
13
|
+
method
|
14
|
+
end
|
15
|
+
|
16
|
+
def log_task(message)
|
17
|
+
puts
|
18
|
+
say_status 'task', "#{method_to_sentence(message.to_s)}:", :yellow
|
19
|
+
puts '-'*80, ''; sleep 0.25
|
20
|
+
end
|
21
|
+
|
22
|
+
def git_commit(message)
|
23
|
+
git add: '-A'
|
24
|
+
git commit: "-m '#{message}'"
|
25
|
+
end
|
26
|
+
|
27
|
+
def git_config(field)
|
28
|
+
command = "git config --global user.#{field}"
|
29
|
+
git_field_value = run(command, capture: true).gsub("\n", '')
|
30
|
+
default_value = "YOUR_#{field.upcase}"
|
31
|
+
|
32
|
+
git_field_value.to_s.empty? ? default_value : git_field_value
|
33
|
+
end
|
34
|
+
|
35
|
+
def copy_from_local_gem(source, dest = '')
|
36
|
+
dest = source if dest.empty?
|
37
|
+
|
38
|
+
base_path = "#{File.expand_path File.dirname(__FILE__)}/includes/role"
|
39
|
+
|
40
|
+
run "mkdir -p #{File.dirname(dest)}" unless Dir.exist?(File.dirname(dest))
|
41
|
+
run "cp -f #{base_path}/#{source} #{dest}"
|
42
|
+
end
|
43
|
+
|
44
|
+
# ---
|
45
|
+
|
46
|
+
def delete_generated_rails_code
|
47
|
+
log_task __method__
|
48
|
+
|
49
|
+
run 'rm -rf * .git .gitignore'
|
50
|
+
end
|
51
|
+
|
52
|
+
def add_role_directory
|
53
|
+
log_task __method__
|
54
|
+
|
55
|
+
run "mkdir -p #{app_name}"
|
56
|
+
run "mv #{app_name}/* ."
|
57
|
+
run "rm -rf #{app_name}"
|
58
|
+
git :init
|
59
|
+
git_commit 'Initial commit'
|
60
|
+
end
|
61
|
+
|
62
|
+
def add_gitignore
|
63
|
+
log_task __method__
|
64
|
+
|
65
|
+
copy_from_local_gem '../common/.gitignore', '.gitignore'
|
66
|
+
git_commit 'Add .gitignore'
|
67
|
+
end
|
68
|
+
|
69
|
+
def add_main_role
|
70
|
+
log_task __method__
|
71
|
+
|
72
|
+
folders = %w(defaults files handlers tasks templates)
|
73
|
+
|
74
|
+
run "mkdir #{folders.join(' ')}"
|
75
|
+
|
76
|
+
folders.delete_if { |folder| folder == 'files' || folder == 'templates' }
|
77
|
+
folders.each do |folder|
|
78
|
+
run "echo '---\n# #{folder} go here' > #{folder}/main.yml"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def add_license
|
83
|
+
log_task __method__
|
84
|
+
|
85
|
+
author_name = git_config 'name'
|
86
|
+
author_email = git_config 'email'
|
87
|
+
|
88
|
+
copy_from_local_gem '../common/LICENSE', 'LICENSE'
|
89
|
+
gsub_file 'LICENSE', 'Time.now.year', Time.now.year.to_s
|
90
|
+
gsub_file 'LICENSE', 'author_name', author_name
|
91
|
+
gsub_file 'LICENSE', 'author_email', author_email
|
92
|
+
git_commit 'Add MIT license'
|
93
|
+
end
|
94
|
+
|
95
|
+
def add_readme
|
96
|
+
log_task __method__
|
97
|
+
|
98
|
+
role_info = File.basename(app_name).split('_')
|
99
|
+
github_user = role_info[0]
|
100
|
+
role_name = role_info[1]
|
101
|
+
|
102
|
+
copy_from_local_gem 'README.md'
|
103
|
+
gsub_file 'README.md', 'github_user', github_user
|
104
|
+
gsub_file 'README.md', 'role_name', role_name
|
105
|
+
git_commit 'Add readme'
|
106
|
+
end
|
107
|
+
|
108
|
+
def add_meta_information
|
109
|
+
log_task __method__
|
110
|
+
|
111
|
+
author_name = git_config 'name'
|
112
|
+
|
113
|
+
copy_from_local_gem 'meta/main.yml'
|
114
|
+
gsub_file 'meta/main.yml', 'author_name', author_name
|
115
|
+
git_commit 'Add meta information'
|
116
|
+
end
|
117
|
+
|
118
|
+
def add_tests_and_travis
|
119
|
+
log_task __method__
|
120
|
+
|
121
|
+
copy_from_local_gem '.travis.yml'
|
122
|
+
copy_from_local_gem 'tests/main.yml'
|
123
|
+
copy_from_local_gem 'tests/inventory'
|
124
|
+
git_commit 'Add tests and travis-ci'
|
125
|
+
end
|
126
|
+
|
127
|
+
def remove_unused_files_from_git
|
128
|
+
log_task __method__
|
129
|
+
|
130
|
+
git add: '-u'
|
131
|
+
git_commit 'Remove unused files'
|
132
|
+
end
|
133
|
+
|
134
|
+
# ---
|
135
|
+
|
136
|
+
delete_generated_rails_code
|
137
|
+
add_role_directory
|
138
|
+
add_gitignore
|
139
|
+
add_main_role
|
140
|
+
add_license
|
141
|
+
add_readme
|
142
|
+
add_meta_information
|
143
|
+
add_tests_and_travis
|
144
|
+
remove_unused_files_from_git
|
data/lib/orats/version.rb
CHANGED
@@ -49,6 +49,36 @@ class TestCLI < Minitest::Test
|
|
49
49
|
assert_playbook target_path
|
50
50
|
end
|
51
51
|
|
52
|
+
def test_role
|
53
|
+
@target_path = 'githubname.myrole'
|
54
|
+
@extra_flags = '-r ansible-myrole'
|
55
|
+
|
56
|
+
out, err = capture_orats('role')
|
57
|
+
|
58
|
+
assert_match /success/, out, err
|
59
|
+
|
60
|
+
absolute_target_path = "#{TEST_PATH}/#{@target_path}"
|
61
|
+
|
62
|
+
assert_path "#{absolute_target_path}/.gitignore"
|
63
|
+
assert_path "#{absolute_target_path}/.travis.yml"
|
64
|
+
assert_path "#{absolute_target_path}/README.md"
|
65
|
+
assert_path "#{absolute_target_path}/LICENSE"
|
66
|
+
assert_path "#{absolute_target_path}/tests"
|
67
|
+
assert_path "#{absolute_target_path}/tests/main.yml"
|
68
|
+
assert_path "#{absolute_target_path}/tests/inventory"
|
69
|
+
refute_path "#{absolute_target_path}/files/main.yml"
|
70
|
+
refute_path "#{absolute_target_path}/templates/main.yml"
|
71
|
+
|
72
|
+
meta_main = IO.read("#{absolute_target_path}/meta/main.yml")
|
73
|
+
readme = IO.read("#{absolute_target_path}/README.md")
|
74
|
+
tests_main = IO.read("#{absolute_target_path}/tests/main.yml")
|
75
|
+
|
76
|
+
refute meta_main.include?('author_name')
|
77
|
+
assert_count readme, 'githubname.myrole', 2
|
78
|
+
assert_count readme, 'ansible-myrole', 3
|
79
|
+
assert_count tests_main, 'myrole', 1
|
80
|
+
end
|
81
|
+
|
52
82
|
def test_diff
|
53
83
|
assert_diff
|
54
84
|
|
@@ -136,6 +166,7 @@ class TestCLI < Minitest::Test
|
|
136
166
|
|
137
167
|
assert_orats 'playbook', 'success'
|
138
168
|
assert_path "#{TEST_PATH}/#{@target_path}/Galaxyfile"
|
169
|
+
assert_ansible_yaml "#{TEST_PATH}/#{@target_path}/common.yml"
|
139
170
|
assert_ansible_yaml "#{TEST_PATH}/#{@target_path}/site.yml"
|
140
171
|
end
|
141
172
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: orats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Janetakis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -93,9 +93,11 @@ files:
|
|
93
93
|
- lib/orats/commands/project/exec.rb
|
94
94
|
- lib/orats/commands/project/rails.rb
|
95
95
|
- lib/orats/commands/project/server.rb
|
96
|
+
- lib/orats/commands/role.rb
|
96
97
|
- lib/orats/commands/ui.rb
|
97
98
|
- lib/orats/templates/auth.rb
|
98
99
|
- lib/orats/templates/base.rb
|
100
|
+
- lib/orats/templates/includes/common/.gitignore
|
99
101
|
- lib/orats/templates/includes/common/LICENSE
|
100
102
|
- lib/orats/templates/includes/inventory/group_vars/all.yml
|
101
103
|
- lib/orats/templates/includes/inventory/hosts
|
@@ -149,8 +151,15 @@ files:
|
|
149
151
|
- lib/orats/templates/includes/new/rails/test/fixtures/accounts.yml
|
150
152
|
- lib/orats/templates/includes/new/rails/test/models/account_test.rb
|
151
153
|
- lib/orats/templates/includes/playbook/Galaxyfile
|
154
|
+
- lib/orats/templates/includes/playbook/common.yml
|
152
155
|
- lib/orats/templates/includes/playbook/site.yml
|
156
|
+
- lib/orats/templates/includes/role/.travis.yml
|
157
|
+
- lib/orats/templates/includes/role/README.md
|
158
|
+
- lib/orats/templates/includes/role/meta/main.yml
|
159
|
+
- lib/orats/templates/includes/role/tests/inventory
|
160
|
+
- lib/orats/templates/includes/role/tests/main.yml
|
153
161
|
- lib/orats/templates/playbook.rb
|
162
|
+
- lib/orats/templates/role.rb
|
154
163
|
- lib/orats/version.rb
|
155
164
|
- orats.gemspec
|
156
165
|
- test/integration/cli_test.rb
|