petra 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MmMwZjJkODBiMTM2ZjEwYTZjOTdhNGJmNGExMTVkNjkwNjQ3MzNhNQ==
4
+ ZDY5NWFlMmY0MDgxODYyMjM2ZTMwNGE3NDQzN2JiNzJiYTM2Mzg3ZQ==
5
5
  data.tar.gz: !binary |-
6
- YTgzNjFhMzhlNzFlYWY4MjY0ODczOGY5YTQ4YzZiNTY4YTY5M2FjNg==
6
+ ZWMyNzM3YTQ1NDJhMjY5YTRlOGY3ODEyYTE4YzhjNDllMmJlOTVmOA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ZDRkZjk0MDM4ODVhMGYwZmVkZWI2YjMyYmI2Y2FhNjMzMWE4YWY2MDQ1OGVk
10
- NjhhNWI4NTExYTJiNzg4MzA4YTBmZjMwYjZhMWRiOWMyNzE3ZjE4ZGVkZDg4
11
- NmIxZDkyYTQ0NWFlNGRkYjQ0MGZjNTA4MmMwYmJlYjg4YmUxZWI=
9
+ YmRhODNlYjM2OWM0MzRkZDBhNmFlYWRlNGM2MWNhYzY4MGQ4ZDdhMGQyZjlj
10
+ OGJlZjdiODA1YWJiNGYwMzdiZjUyYTVhYWVlMGRlYTg1MGYxODNjZGFlZWVk
11
+ ZWNiNDNkZjM1OGJhYzc5MzU0MzQzYTkwYTdkNWQ5MjJmYzUxMjA=
12
12
  data.tar.gz: !binary |-
13
- NGVjZjZiYTZmMDUzMjdjMzI5NjlkN2VhMzM5MDQzZjUzNzg5NTc5M2FhYTQ4
14
- NzlmOTJhZDk2NzljYTBiNzM5ZmZlYjdmZjRlMjMzMjQ5ZDBlOWJkMmZjNWVk
15
- YmM3YjZjMGM0NGRjMzY1Y2I2ZTY1YTgwNGE5ZTEwNDY3MDY0OWE=
13
+ MjM0YzAwZjc2NDJiZTMyMzJmMzUzYTJiNTM2OGJmNTdhMjM5ODg5ZDZlYWZh
14
+ NjAwMzg0ZTc2Yzg4ZGEyYjU0ODNkOGQ2YmE5NGYxNTVkOWViMjE5ZDE0ZGU3
15
+ NzY2NDU5M2UzNWY3OGQzYjI1ZGU0ZTU5ODgzYjdhNDQ3M2I0MzY=
@@ -0,0 +1,11 @@
1
+ # Versions
2
+
3
+ ## 0.0.2
4
+
5
+ * simplified many subcommands down to just `generate`
6
+ * updated options and calls to reflect new ansible/vagrant versions
7
+
8
+ ## 0.0.1
9
+
10
+ * initial version
11
+ * pushed to rubygems
data/Gemfile CHANGED
@@ -1,4 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in petra.gemspec
4
3
  gemspec
4
+
5
+ gem 'pry'
data/README.md CHANGED
@@ -1,24 +1,34 @@
1
1
  # Petra
2
2
 
3
- A toolkit for managing Ansible projects.
3
+ A toolkit for managing Ansible/Vagrant projects.
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Run the following command on your shell to install the gem, including
8
+ the CLI.
8
9
 
9
- gem 'petra'
10
+ gem install petra
10
11
 
11
- And then execute:
12
+ ## Usage
12
13
 
13
- $ bundle
14
+ Start by creating a new project:
14
15
 
15
- Or install it yourself as:
16
+ petra generate project my-sweet-project
16
17
 
17
- $ gem install petra
18
+ Or, use the shortcut:
18
19
 
19
- ## Usage
20
+ petra new my-sweet-project
21
+
22
+ This includes a default machine configuration with the name `default`.
23
+ Machines are Petra's way of describing the different (proto)types of
24
+ boxes that your project may need. If you want to call it `webserver`
25
+ instead, use the `-m` option:
26
+
27
+ petra new my-sweet-project -m webserver
28
+
29
+ When you're ready, `cd` into your project and run `vagrant up`.
20
30
 
21
- TODO: Write usage instructions here
31
+ That's all for now :)
22
32
 
23
33
  ## Contributing
24
34
 
data/bin/petra CHANGED
@@ -8,8 +8,15 @@ BEGIN {
8
8
  require 'petra/cli'
9
9
  rescue LoadError => e
10
10
  raise e if has_retried
11
- libpath = File.expand_path "#{ __FILE__ }/../../lib"
12
- $LOAD_PATH.unshift libpath
11
+
12
+ rootdir = File.expand_path "#{ __FILE__ }/../.."
13
+ gitdir = "#{ rootdir }/.git"
14
+
15
+ if Dir.exists?( gitdir )
16
+ ENV[ 'BUNDLE_GEMFILE' ] ||= "#{ rootdir }/Gemfile"
17
+ require 'bundler/setup'
18
+ end
19
+
13
20
  has_retried = true
14
21
  retry
15
22
  end
@@ -1,4 +1,6 @@
1
1
  require "petra/version"
2
2
 
3
3
  module Petra
4
+ ROOTPATH = File.expand_path "#{ __FILE__ }/../.."
5
+ LIBPATH = "#{ ROOTPATH }/lib"
4
6
  end
@@ -1,6 +1,25 @@
1
+ require 'petra'
1
2
  require 'thor'
2
3
 
3
4
  module Petra
4
5
  class CLI < Thor
6
+ desc \
7
+ 'new <name>',
8
+ 'Shortcut to create a new Petra project named <name>'
9
+
10
+ option \
11
+ :machine_name,
12
+ :aliases => '-m',
13
+ :default => 'default',
14
+ :desc => 'The name of the first machine in the project.'
15
+
16
+ def new( project_name )
17
+ invoke \
18
+ Generate,
19
+ :project
20
+ end
5
21
  end
6
22
  end
23
+
24
+ require 'petra/cli/subcommand'
25
+ require 'petra/cli/generate'
@@ -0,0 +1,126 @@
1
+ module Petra
2
+ class CLI
3
+ Subcommand :Generate do
4
+ attr_reader \
5
+ :machine_name,
6
+ :playbook_name,
7
+ :project_name,
8
+ :seed_name
9
+
10
+ command_description 'Template various parts of, or whole, Petra projects'
11
+ command_invocation 'generate'
12
+ command_usage 'generate <subcommand> <...args>'
13
+
14
+ desc \
15
+ 'machine <name>',
16
+ 'Create a new machine named <name>'
17
+
18
+ def machine( machine_name )
19
+ @machine_name ||= machine_name
20
+
21
+ template_new_machine!
22
+
23
+ invoke_new_seed!
24
+ invoke_new_playbook!
25
+ end
26
+
27
+ desc \
28
+ 'playbook <name>',
29
+ 'Create a new playbook named <name>'
30
+
31
+ def playbook( playbook_name )
32
+ @playbook_name ||= playbook_name
33
+ template_new_playbook!
34
+ end
35
+
36
+ desc \
37
+ 'project <name>',
38
+ 'Create a new Petra project named <name>'
39
+
40
+ option \
41
+ :machine_name,
42
+ :aliases => '-m',
43
+ :default => 'default',
44
+ :desc => 'The name of the first machine in the project.'
45
+
46
+ def project( project_name )
47
+ @project_name ||= project_name
48
+
49
+ template_new_project_directory!
50
+
51
+ inside project_name do
52
+ invoke_new_machine!
53
+ end
54
+ end
55
+
56
+ desc \
57
+ 'seed <name>',
58
+ 'Create a new seed named <name>'
59
+
60
+ def seed( seed_name )
61
+ @seed_name ||= seed_name
62
+ template_new_seed!
63
+ end
64
+
65
+ no_commands do
66
+ def invoke_new_playbook!
67
+ invoke \
68
+ Generate,
69
+ :playbook,
70
+ [ machine_name ]
71
+ end
72
+
73
+ def invoke_new_seed!
74
+ invoke \
75
+ Generate,
76
+ :seed,
77
+ [ machine_name ]
78
+ end
79
+
80
+ def invoke_new_machine!
81
+ invoke \
82
+ Generate,
83
+ :machine,
84
+ [ machine_name ],
85
+ Hash.new
86
+ end
87
+
88
+ def machine_name
89
+ @machine_name or options.machine_name
90
+ end
91
+
92
+ def petra_version
93
+ Petra::VERSION
94
+ end
95
+
96
+ def template_new_machine!
97
+ empty_directory 'machines'
98
+
99
+ directory \
100
+ 'machine/new',
101
+ '.'
102
+ end
103
+
104
+ def template_new_playbook!
105
+ directory \
106
+ 'playbook/new',
107
+ '.'
108
+ end
109
+
110
+ def template_new_project_directory!
111
+ directory \
112
+ 'project/new',
113
+ project_name
114
+ end
115
+
116
+ def template_new_seed!
117
+ empty_directory 'seeds'
118
+
119
+ directory \
120
+ 'seed/new',
121
+ '.'
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,53 @@
1
+ require 'petra/patches/thor'
2
+
3
+ module Petra
4
+ class CLI
5
+ class Subcommand < Thor
6
+ include Thor::Actions
7
+
8
+ module ClassMethods
9
+ %w(
10
+ description
11
+ invocation
12
+ usage
13
+ ).each do | attr |
14
+ module_eval <<-___ , __FILE__ , __LINE__
15
+ def command_#{ attr }( val = nil )
16
+ if val
17
+ @_command_#{ attr } ||= val
18
+ end
19
+
20
+ @_command_#{ attr }
21
+ end
22
+ ___
23
+ end
24
+ end
25
+
26
+ def self.inherited( klass )
27
+ klass.source_root "#{ LIBPATH }/sources"
28
+ klass.extend ClassMethods
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def self.Subcommand( command_name , &block )
35
+ subcommand_class =
36
+ Class.new \
37
+ Subcommand,
38
+ &block
39
+
40
+ const_set \
41
+ command_name,
42
+ subcommand_class
43
+
44
+ register \
45
+ subcommand_class,
46
+ subcommand_class.command_invocation,
47
+ subcommand_class.command_usage,
48
+ subcommand_class.command_description
49
+
50
+ subcommand_class
51
+ end
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ require 'petra/patches/thor/command'
@@ -0,0 +1,40 @@
1
+ class Thor
2
+ class Command
3
+ def formatted_usage(klass, namespace = true, subcommand = false)
4
+ if namespace
5
+ namespace = klass.namespace
6
+ formatted = "#{namespace.gsub(/^(default)/,'')}:"
7
+ end
8
+ formatted = "#{klass.namespace.split(':').last} " if subcommand
9
+
10
+ formatted ||= ""
11
+
12
+ # PATCH :: properly display subcommands
13
+ #
14
+ # Tasks/Commands registered in subcommands incorrectly
15
+ # display at the top level with the default Thor help
16
+ # task. This attempts to fix the issue.
17
+ #
18
+ # WARN :: it probably won't work for subcommands of subcommands
19
+ #
20
+ if !subcommand and klass.ancestors.include?( Petra::CLI::Subcommand )
21
+ formatted << "#{ klass.command_invocation } "
22
+ end
23
+
24
+ # Add usage with required arguments
25
+ formatted << if klass && !klass.arguments.empty?
26
+ usage.to_s.gsub(/^#{name}/) do |match|
27
+ match << " " << klass.arguments.map{ |a| a.usage }.compact.join(' ')
28
+ end
29
+ else
30
+ usage.to_s
31
+ end
32
+
33
+ # Add required options
34
+ formatted << " #{required_options}"
35
+
36
+ # Strip and go!
37
+ formatted.strip
38
+ end
39
+ end
40
+ end
@@ -1,3 +1,3 @@
1
1
  module Petra
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,17 @@
1
+ App.machine_configs.register '<%= machine_name %>' do | base_config |
2
+ base_config.vm.define :<%= machine_name %> do | config |
3
+ config.vm.hostname = '<%= machine_name %>'
4
+
5
+ config.vm.network \
6
+ :forwarded_port,
7
+ :guest => 22,
8
+ :host => App.seeds[ '<%= machine_name %>' ][ 'ansible_ssh_port' ]
9
+
10
+ config.vm.provision :ansible do | ansible |
11
+ ansible.raw_arguments = '--extra-vars=@seeds/<%= machine_name %>.seed.yml'
12
+ ansible.inventory_path = 'hosts/local.hosts'
13
+ ansible.playbook = '<%= machine_name %>.yml'
14
+ ansible.verbose = true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,5 @@
1
+ ---
2
+ - name: <%= playbook_name %> machine playbook
3
+ hosts: all
4
+ roles:
5
+ - common
@@ -0,0 +1,9 @@
1
+ /.bundle
2
+ /.vagrant
3
+ /.venv
4
+
5
+ /seeds/*.seed.rb
6
+ /vendor/bundle
7
+
8
+ *.crt
9
+ *.key
@@ -0,0 +1,6 @@
1
+ # <%= project_name %>
2
+
3
+ TODO: Write documentation about your infrastructure
4
+
5
+ ------------------------
6
+ Generated Using [Petra](https://github.com/cookrn/petra) v<%= petra_version %>
@@ -0,0 +1,21 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ load 'lib/app.rb'
5
+
6
+ Vagrant.configure( '2' ) do | config |
7
+ config.vm.box = 'precise64'
8
+ config.vm.box_url = 'http://files.vagrantup.com/precise64.box'
9
+
10
+ config.vm.provider :virtualbox do | vb |
11
+ vb.customize [
12
+ 'modifyvm',
13
+ :id,
14
+ '--memory',
15
+ '512'
16
+ ]
17
+ end
18
+
19
+ App.load_seeds!
20
+ App.load_machines! config
21
+ end
@@ -0,0 +1 @@
1
+ 127.0.0.1
@@ -0,0 +1,63 @@
1
+ require 'yaml'
2
+
3
+ module App
4
+ extend self
5
+
6
+ attr_accessor \
7
+ :seeds,
8
+ :machine_configs,
9
+ :root
10
+
11
+ class Hashy < Hash
12
+ alias_method :__old_get__ , :[]
13
+
14
+ def get( key )
15
+ if has_key?( key )
16
+ __old_get__ key
17
+ else
18
+ self[ key ] = self.class.new
19
+ end
20
+ end
21
+ alias_method :[] , :get
22
+
23
+ def register( key , &block )
24
+ self[ key ] = block
25
+ end
26
+ end
27
+
28
+ self.machine_configs = Hashy.new
29
+ self.seeds = Hashy.new
30
+
31
+ self.root = File.expand_path "#{ __FILE__ }/../.."
32
+
33
+ def load_seed!( seed )
34
+ seed_name = seed.split( '/' ).last.split( '.' ).first
35
+ data = YAML.load_file seed
36
+ seeds[ seed_name ] = data
37
+ end
38
+
39
+ def load_seeds!
40
+ Dir[ "#{ root }/seeds/**/**.seed.yml" ].each do | seed |
41
+ load_seed! seed
42
+ end
43
+ end
44
+
45
+ def load_machines!( config )
46
+ Dir[ "#{ root }/machines/**/**.vagrant.rb" ].each do | machine |
47
+ load machine
48
+ end
49
+
50
+ machines =
51
+ if ENV[ 'MACHINES' ]
52
+ ENV[ 'MACHINES' ].split ','
53
+ else
54
+ machine_configs.keys
55
+ end
56
+
57
+ machines.each do | machine |
58
+ if machine_config = machine_configs[ machine ]
59
+ instance_exec config , &machine_config
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,16 @@
1
+ ---
2
+ - name: update apt
3
+ apt: update_cache=yes cache_valid_time=3600
4
+ sudo: yes
5
+
6
+ - name: install common packages
7
+ apt: pkg={{ item }}
8
+ sudo: yes
9
+ with_items:
10
+ - curl
11
+ - git
12
+ - screen
13
+ - subversion
14
+ - traceroute
15
+ - vim
16
+ - build-essential
@@ -0,0 +1,16 @@
1
+ # -*- mode: yaml -*-
2
+ # vi: set ft=yaml :
3
+
4
+ # This is an example app seed file. It will not be ignored by
5
+ # the default `.gitignore` file included in this repository.
6
+ # Use it to keep track of the required Ansible key/value
7
+ # variable pairs required by your playbooks so that other users
8
+ # of this repository will simply need to copy in the required
9
+ # secret values. See the example key `super_secret_key` included
10
+ # below.
11
+
12
+ ---
13
+ ansible_ssh_port: 42000
14
+ ansible_ssh_private_key_file: ~/.vagrant.d/insecure_private_key
15
+ ansible_ssh_user: vagrant
16
+ super_secret_key: example not real super secret value
@@ -0,0 +1,20 @@
1
+ # -*- mode: yaml -*-
2
+ # vi: set ft=yaml :
3
+
4
+ # This is a real, usable seed file. It will be ignored by
5
+ # the default `.gitignore` file included in this repository
6
+ # since it may contain actual secret values not meant to be
7
+ # included in your source repository. See the example key
8
+ # `super_secret_key` included below.
9
+
10
+ # Ultimately, these values will be passed as `--extra-vars` to the
11
+ # `ansible-playbook` command for provisioning your machine(s). This
12
+ # happens either by passing them to Vagrant during the machine
13
+ # provisioning step or during a playbook run using the `petra`
14
+ # command.
15
+
16
+ ---
17
+ ansible_ssh_port: 42000
18
+ ansible_ssh_private_key_file: ~/.vagrant.d/insecure_private_key
19
+ ansible_ssh_user: vagrant
20
+ super_secret_key: actual super secret value
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Petra::VERSION
9
9
  spec.authors = ["Ryan Cook"]
10
10
  spec.email = ["cookrn@gmail.com"]
11
- spec.description = %q{A toolkit for managing Ansible projects.}
11
+ spec.description = %q{A toolkit for managing Ansible/Vagrant projects.}
12
12
  spec.summary = "#{ spec.name } v#{ spec.version }"
13
13
  spec.homepage = "https://github.com/cookrn/petra"
14
14
  spec.license = "MIT"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: petra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Cook
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-07 00:00:00.000000000 Z
11
+ date: 2013-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -52,7 +52,7 @@ dependencies:
52
52
  - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: A toolkit for managing Ansible projects.
55
+ description: A toolkit for managing Ansible/Vagrant projects.
56
56
  email:
57
57
  - cookrn@gmail.com
58
58
  executables:
@@ -61,6 +61,7 @@ extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
63
  - .gitignore
64
+ - CHANGELOG.md
64
65
  - Gemfile
65
66
  - LICENSE.txt
66
67
  - README.md
@@ -68,7 +69,21 @@ files:
68
69
  - bin/petra
69
70
  - lib/petra.rb
70
71
  - lib/petra/cli.rb
72
+ - lib/petra/cli/generate.rb
73
+ - lib/petra/cli/subcommand.rb
74
+ - lib/petra/patches/thor.rb
75
+ - lib/petra/patches/thor/command.rb
71
76
  - lib/petra/version.rb
77
+ - lib/sources/machine/new/machines/%machine_name%.vagrant.rb.tt
78
+ - lib/sources/playbook/new/%playbook_name%.yml.tt
79
+ - lib/sources/project/new/.gitignore
80
+ - lib/sources/project/new/README.md.tt
81
+ - lib/sources/project/new/Vagrantfile
82
+ - lib/sources/project/new/hosts/local.hosts
83
+ - lib/sources/project/new/lib/app.rb
84
+ - lib/sources/project/new/roles/common/tasks/main.yml
85
+ - lib/sources/seed/new/seeds/%seed_name%.seed.example.yml
86
+ - lib/sources/seed/new/seeds/%seed_name%.seed.yml
72
87
  - petra.gemspec
73
88
  homepage: https://github.com/cookrn/petra
74
89
  licenses:
@@ -93,5 +108,5 @@ rubyforge_project:
93
108
  rubygems_version: 2.0.4
94
109
  signing_key:
95
110
  specification_version: 4
96
- summary: petra v0.0.1
111
+ summary: petra v0.0.2
97
112
  test_files: []