ansible_make_role 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 323dcdb66550dda4f21397b66c21524a16da617d120d05cd9382607cbe20e5d1
4
+ data.tar.gz: d9332ca69d757e758f4ec996c2eb86a4676586bf24e457b47d6a6edbcaa0d8c3
5
+ SHA512:
6
+ metadata.gz: b461800f749cee4148bc39ee1221403830d31e4b0894d8b27c9dbd89b9297c9fc4bdaf0ad16e4ad998a3e7d231299b9fba42fb52dc3a14bdd58dedf9dab29abd
7
+ data.tar.gz: 480a4a450cb337cb7272a300fb37eb69784e454b54600cef8a618da8e9f58251f2e57e5d88fa19db241f1158a549476141d123b69a6c3e703714f68a709431b6
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # Ignore auto-generated main file
14
+ /main
15
+
16
+ # Ignore Gemfile.lock. See https://stackoverflow.com/questions/4151495/should-gemfile-lock-be-included-in-gitignore
17
+ /Gemfile.lock
18
+
19
+ # Put your personal ignore files in /home/clr/.config/git/ignore
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.6.0
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 1.17.2
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in ansible_make_role.gemspec
6
+ gemspec
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # ansible-make-role
2
+
3
+ Pre-compiler that turns `make.yml` files into Ansible roles
4
+
5
+ ## Usage
6
+
7
+ ```shell
8
+ ansible-make-role -f|--force -t|--target-dir=DIR -v|--verbose DIR...
9
+ ```
10
+
11
+ `ansible-make-role` expects a `make.yml` file in each of the given directories
12
+ and generate a Ansible role from each of them. The generated files will reside
13
+ in subdirectories of the directory of the `make.yml` file but it can be
14
+ overridden by the --target-dir option. `ansible-make-role` only generates
15
+ out-of-date files unless the --force option is used. Use the `--verbose` option
16
+ to get information about the process
17
+
18
+ ## Description
19
+
20
+ The `make.yml` contains a section for each generated file so that eg. the
21
+ `tasks` section becomes the `tasks/main.yml` file. The supported sections are
22
+ `defaults`, `vars`, `tasks`, and `handlers`. Anything outside of those sections
23
+ (notably `dependencies`) goes to the `meta/main.yml` file
24
+
25
+ Example:
26
+
27
+ ```yaml
28
+ ---
29
+ dependencies: # Goes to meta/main.yml
30
+ - role: rails-server
31
+
32
+ defaults: # Goes to defaults/main.yml
33
+ appl_name: "myapp"
34
+ appl_domain: "mydomain.com"
35
+
36
+ vars: # Goes to vars/main.yml
37
+ appl_host: "{{ appl_name}}.{{ appl_domain }}"
38
+
39
+ tasks: # Goes to tasks/main.yml
40
+ - name: "Ensure Apache"
41
+ yum: name=httpd state=present
42
+ notify: restart_httpd
43
+
44
+ - name: "Ensure Apache is enabled"
45
+ service: name=httpd enabled=yes
46
+
47
+ handlers: # Goes to handlers/main.yml"
48
+ - name: restart_httpd
49
+ servide name=httpd state=restarted
50
+
51
+ ...
52
+ ```
53
+
54
+ ## Installation
55
+
56
+ Install it for the current ruby using:
57
+
58
+ $ gem install ansible_make_role
59
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,47 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "ansible_make_role/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ansible_make_role"
8
+ spec.version = AnsibleMakeRole::VERSION
9
+ spec.authors = ["Claus Rasmussen"]
10
+ spec.email = ["claus.l.rasmussen@gmail.com"]
11
+
12
+ spec.summary = %q{Make Ansible role from make.yml file}
13
+ spec.description = %q{
14
+ Instead of having an Ansible role per-directory
15
+ main.yml file, ansible-make-role processes a make.yml
16
+ file in the role directory and generates the main.yml
17
+ files from that. In make.yml each main.yml definition
18
+ is contained in a per-file section: 'defaults',
19
+ 'vars', 'tasks', and 'handlers'. Definitions outside
20
+ of those sections (notably 'dependencies') are going
21
+ to the meta/main.yml file
22
+ }
23
+ spec.homepage = "http://github.com/clrgit/ansible_make_role"
24
+
25
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
26
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
27
+ if spec.respond_to?(:metadata)
28
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
29
+ else
30
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes"
31
+ end
32
+
33
+ # Specify which files should be added to the gem when it is released.
34
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
35
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
36
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
37
+ end
38
+ spec.bindir = "exe"
39
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
40
+ spec.require_paths = ["lib"]
41
+
42
+ spec.add_development_dependency "bundler", "~> 1.17"
43
+ spec.add_development_dependency "rake", "~> 10.0"
44
+ spec.add_development_dependency "rspec", "~> 3.0"
45
+
46
+ spec.add_dependency "shellopts", "0.9.3"
47
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ansible_make_role"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'ansible_make_role.rb'
4
+ require "shellopts"
5
+
6
+ USAGE = "f,force t,target-dir=DIR v,verbose -- DIRECTORY..."
7
+
8
+ force = false
9
+ target_dir = nil
10
+ verbose = false
11
+
12
+ args = ShellOpts.process(USAGE, ARGV) { |opt, arg|
13
+ case opt
14
+ when '-f', '--force'; force = true
15
+ when '-t', '--target-dir'; target_dir = arg
16
+ when '-v', '--verbose'; verbose = true
17
+ end
18
+ }
19
+ args.size > 0 or args << "."
20
+
21
+ include AnsibleMakeRole
22
+ for source in args
23
+ File.directory?(source) or ShellOpts.error "Not a directory: #{source.inspect}"
24
+ target = target_dir || File.dirname(source)
25
+ puts "Source: #{source}"
26
+ puts "Target: #{target}"
27
+ make_role(source, target, verbose: verbose, force: force)
28
+ end
@@ -0,0 +1,77 @@
1
+ require "ansible_make_role/version"
2
+
3
+ require "fileutils"
4
+
5
+ module AnsibleMakeRole
6
+ class Error < StandardError; end
7
+ # Your code goes here...
8
+
9
+ # source is a file, target is a directory. Target can be nil and defaults to
10
+ # dirname of source
11
+ def compile_role(source, target = File.dirname(source), verbose: false)
12
+ sections = {
13
+ "meta" => [],
14
+ "defaults" => [],
15
+ "vars" => [],
16
+ "tasks" => [],
17
+ "handlers" => []
18
+ }
19
+ lines = sections["meta"]
20
+
21
+ puts "Parsing #{source}" if verbose
22
+ File.readlines(source).each { |line|
23
+ line.chomp!
24
+ next if line =~ /^---\s*$/
25
+ if line =~ /^(\w+)\s*:/
26
+ section = $1
27
+ if sections.key?(section) # Built-in section?
28
+ lines = sections[section]
29
+ else # Everything else goes to the meta file incl. section header
30
+ lines = sections["meta"]
31
+ lines << line
32
+ end
33
+ else
34
+ lines << line
35
+ end
36
+ }
37
+
38
+ sections.each { |section, lines|
39
+ next if lines.empty? && section != "meta"
40
+ dir = "#{target}/#{section}"
41
+ file = "#{dir}/main.yml"
42
+
43
+ puts "Create #{file}" if verbose
44
+ FileUtils.mkdir_p(dir)
45
+ File.open("#{dir}/main.yml", "w") { |f|
46
+ f.puts "---" if section != "meta"
47
+ unindent(lines).each { |l| f.puts l }
48
+ }
49
+ }
50
+ end
51
+
52
+ def make_role(source_dir, target_dir = source_dir, verbose: false, force: false)
53
+ source = "#{source_dir}/make.yml"
54
+ target = "#{target_dir}/#{File.basename(source_dir)}"
55
+ File.file?(source) or ShellOpts::error "Can't read file #{source.inspect}"
56
+ File.directory?(target_dir) or ShellOpts::error "Can't find directory #{target_dir}"
57
+
58
+ meta_yml = "#{target}/meta/main.yml"
59
+ if force || !File.exist?(meta_yml) || File.mtime(source) > File.mtime(meta_yml)
60
+ compile_role(source, target, verbose: verbose)
61
+ else
62
+ puts "#{target} is up to date" if verbose
63
+ end
64
+ end
65
+
66
+ private
67
+ # Unindent lines by the indentation of the first non-comment and non-blank
68
+ # line
69
+ def unindent(lines)
70
+ line = lines.find { |l| l !~ /^\s*#/ && l !~ /^\s*$/ }
71
+ return lines if line.nil?
72
+ line =~ /^(\s*)/
73
+ prefix = $1.dup
74
+ lines.map { |l| l.sub(/^#{prefix}/, "") }
75
+ end
76
+
77
+ end
@@ -0,0 +1,3 @@
1
+ module AnsibleMakeRole
2
+ VERSION = "0.7.0"
3
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansible_make_role
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - Claus Rasmussen
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: shellopts
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.9.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.9.3
69
+ description: "\n Instead of having an Ansible role per-directory\n
70
+ \ main.yml file, ansible-make-role processes a make.yml\n
71
+ \ file in the role directory and generates the main.yml\n
72
+ \ files from that. In make.yml each main.yml definition\n
73
+ \ is contained in a per-file section: 'defaults',\n 'vars',
74
+ 'tasks', and 'handlers'. Definitions outside\n of those
75
+ sections (notably 'dependencies') are going\n to the meta/main.yml
76
+ file\n "
77
+ email:
78
+ - claus.l.rasmussen@gmail.com
79
+ executables:
80
+ - ansible-make-role
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - ".rspec"
86
+ - ".ruby-version"
87
+ - ".travis.yml"
88
+ - Gemfile
89
+ - README.md
90
+ - Rakefile
91
+ - ansible_make_role.gemspec
92
+ - bin/console
93
+ - bin/setup
94
+ - exe/ansible-make-role
95
+ - lib/ansible_make_role.rb
96
+ - lib/ansible_make_role/version.rb
97
+ homepage: http://github.com/clrgit/ansible_make_role
98
+ licenses: []
99
+ metadata:
100
+ allowed_push_host: https://rubygems.org
101
+ post_install_message:
102
+ rdoc_options: []
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubygems_version: 3.0.1
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Make Ansible role from make.yml file
120
+ test_files: []