ansible-utils 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4e2e4706605599532f5bd35b3576e4192d9d9c65ebc0575b39f9f5f8ad8843cb
4
+ data.tar.gz: f350353767ba75a8fd7c2b8de9e39ebe08a5fa478662951891714fbad20c9cf1
5
+ SHA512:
6
+ metadata.gz: 7b9c279fd741799d5f8270a8ddcfbdd5898174d6da17bcfad43031be1dfb52a05c0f789e20de1d2b7192037ee7868f685c69d3728d631cbddf72ec955dc3eceb
7
+ data.tar.gz: 2f52f0f7a042a1323c32ffc0fb28d4e9911e4b965513b6babe685bb7729620e741dd451bf98ff729cf621b6180935a4859614dfff28499ac7f8c59aa3e31fc61
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
@@ -0,0 +1,75 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at krzysztof.maicher@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
75
+
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in pg_export.gemspec
6
+ gemspec
@@ -0,0 +1,63 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ansible-utils (0.1.0)
5
+ commander (~> 4.5)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.1)
11
+ coderay (1.1.3)
12
+ commander (4.5.2)
13
+ highline (~> 2.0.0)
14
+ diff-lcs (1.4.4)
15
+ highline (2.0.3)
16
+ jaro_winkler (1.5.4)
17
+ method_source (1.0.0)
18
+ parallel (1.20.1)
19
+ parser (3.0.0.0)
20
+ ast (~> 2.4.1)
21
+ powerpack (0.1.3)
22
+ pry (0.13.1)
23
+ coderay (~> 1.1)
24
+ method_source (~> 1.0)
25
+ rainbow (3.0.0)
26
+ rake (13.0.3)
27
+ rspec (3.10.0)
28
+ rspec-core (~> 3.10.0)
29
+ rspec-expectations (~> 3.10.0)
30
+ rspec-mocks (~> 3.10.0)
31
+ rspec-core (3.10.1)
32
+ rspec-support (~> 3.10.0)
33
+ rspec-expectations (3.10.1)
34
+ diff-lcs (>= 1.2.0, < 2.0)
35
+ rspec-support (~> 3.10.0)
36
+ rspec-mocks (3.10.1)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-support (3.10.1)
40
+ rubocop (0.59.2)
41
+ jaro_winkler (~> 1.5.1)
42
+ parallel (~> 1.10)
43
+ parser (>= 2.5, != 2.5.1.1)
44
+ powerpack (~> 0.1)
45
+ rainbow (>= 2.2.2, < 4.0)
46
+ ruby-progressbar (~> 1.7)
47
+ unicode-display_width (~> 1.0, >= 1.0.1)
48
+ ruby-progressbar (1.11.0)
49
+ unicode-display_width (1.7.0)
50
+
51
+ PLATFORMS
52
+ x86_64-linux
53
+
54
+ DEPENDENCIES
55
+ ansible-utils!
56
+ bundler (~> 2.1)
57
+ pry
58
+ rake (~> 13.0)
59
+ rspec (~> 3.4)
60
+ rubocop (~> 0.59.2)
61
+
62
+ BUNDLED WITH
63
+ 2.2.3
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Populate
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,53 @@
1
+ # ansible-utils
2
+
3
+ Ansible tools for our daily workflows.
4
+
5
+ `$ ansible-utils --help`:
6
+
7
+ ```
8
+ NAME:
9
+
10
+ Ansible Utils
11
+
12
+ DESCRIPTION:
13
+
14
+ Utils for managing Ansible projects
15
+
16
+ COMMANDS:
17
+
18
+ config Creates and edits the configuration
19
+ copy_roles Copy playbook roles from generic source
20
+ help Display global or [command] help documentation
21
+ symlink_roles Symlink playbook roles from generic source
22
+
23
+ GLOBAL OPTIONS:
24
+
25
+ -h, --help
26
+ Display help documentation
27
+
28
+ -v, --version
29
+ Display version information
30
+
31
+ -t, --trace
32
+ Display backtrace when an error occurs
33
+ ```
34
+
35
+ ## Setup
36
+
37
+ ```
38
+ $ gem install ansible-utils
39
+ ```
40
+
41
+ Once installed run `$ ansible-utils config` to complete the configuration. You'll need to add the path to the generic roles folder.
42
+
43
+ ## Contributing
44
+
45
+ Bug reports and pull requests are welcome on GitHub at https://github.com/PopulateTools/ansible-utils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
46
+
47
+ ## License
48
+
49
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
50
+
51
+ ## Authors
52
+
53
+ This is a project developed by [Populate](https://populate.tools).
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'ansible_utils/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "ansible-utils"
9
+ spec.version = "0.1.0"
10
+ spec.authors = ['Víctor Martín', 'Fernando Blat']
11
+ spec.email = ['victor@populate.tools', 'fernando@populate.tools']
12
+ spec.summary = "PopulateTools Ansible Utils"
13
+ spec.homepage = "https://github.com/PopulateTools/ansible-utils"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.executables = ['ansible-utils']
18
+ spec.require_paths = ['lib']
19
+ spec.required_ruby_version = '>= 2.7.0'
20
+
21
+ spec.add_dependency "commander", "~> 4.5"
22
+ spec.add_development_dependency 'bundler', '~> 2.1'
23
+ spec.add_development_dependency 'pry'
24
+ spec.add_development_dependency 'rake', '~> 13.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.4'
26
+ spec.add_development_dependency 'rubocop', '~> 0.59.2'
27
+ end
28
+
@@ -0,0 +1,68 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # dependencies
5
+ require "commander/import"
6
+
7
+ # standard lib
8
+ require "yaml"
9
+ require "fileutils"
10
+
11
+ # modules
12
+ require_relative "../lib/ansible_utils/dependency_manager"
13
+ require_relative "../lib/ansible_utils/playbook_helpers"
14
+ require_relative "../lib/ansible_utils/version"
15
+
16
+ include AnsibleUtils::PlaybookHelpers
17
+
18
+ program :name, "Ansible Utils"
19
+ program :version, AnsibleUtils::VERSION
20
+ program :description, "Utils for managing Ansible projects"
21
+
22
+ command :copy_roles do |c|
23
+ c.syntax = "ansible-utils copy_roles <playbook>"
24
+ c.description = "Copy playbook roles from generic source"
25
+ c.option "-f", "--force", "Overwrite existing roles"
26
+ c.action do |args, options|
27
+ options.default force: false
28
+ AnsibleUtils::DependencyManager.new(args.first, options).copy_roles
29
+ end
30
+ end
31
+
32
+ command :symlink_roles do |c|
33
+ c.syntax = "ansible-utils symlink_roles <playbook>"
34
+ c.description = "Symlink playbook roles from generic source"
35
+ c.option "-f", "--force", "Overwrite existing roles"
36
+ c.action do |args, options|
37
+ options.default force: false
38
+ AnsibleUtils::DependencyManager.new(args.first, options).symlink_roles
39
+ end
40
+ end
41
+
42
+ command :config do |c|
43
+ c.syntax = "ansible-utils config"
44
+ c.description = "Check configuration"
45
+ c.action do |args, _|
46
+ if !File.file?(config_file_path)
47
+ puts "[!!] Config file at #{config_file_path} doesn't exist. Creating..."
48
+ puts "[OK] Created file #{config_file_path}. Open it with your editor"
49
+ FileUtils.mkdir_p(File.join(ENV.fetch('HOME'), '.config', 'ansible-utils'))
50
+ File.write(config_file_path, "---\ngeneric_roles_path: ")
51
+ else
52
+ puts "[OK] Config file found. Checking syntax and content..."
53
+ folder = generic_roles_folder
54
+ if folder
55
+ puts "[OK] Syntax is fine"
56
+ else
57
+ puts "[!!] Syntax seems to be wrong, couldn't read value"
58
+ end
59
+ if Dir.exists?(folder)
60
+ puts "[OK] Generic folder exist: #{folder}"
61
+ else
62
+ puts "[!!] Generic folder referenced in the file doesn't exist: #{folder}"
63
+ end
64
+ end
65
+ end
66
+ end
67
+
68
+
@@ -0,0 +1,48 @@
1
+ require_relative "playbook_helpers"
2
+
3
+ module AnsibleUtils
4
+ class DependencyManager
5
+ include PlaybookHelpers
6
+
7
+ attr_reader :playbook_path, :options
8
+
9
+ def initialize playbook_path, options = {}
10
+ @playbook_path = playbook_path
11
+ @options = options
12
+ end
13
+
14
+ def symlink_roles
15
+ paths.each{|path| execute_in_path(:symlink, path) }
16
+ end
17
+
18
+ def copy_roles
19
+ paths.each{|path| execute_in_path(:copy, path) }
20
+ end
21
+
22
+ private
23
+
24
+ def execute_in_path action, path
25
+ populate_ansible_path = File.join(generic_roles_folder, path) if generic_roles_folder
26
+ project_path = File.join(project_folder, path)
27
+ file_utils_method = action == :copy ? :copy_entry : :ln_s
28
+
29
+ if !File.directory?(populate_ansible_path)
30
+ puts "- Ignoring role '#{path}' because it does not exist in populate-ansible"
31
+ else
32
+ dirname = File.dirname(project_path)
33
+ if Dir.exists?(project_path)
34
+ if options.force
35
+ puts "+ Overwritting role '#{path}'"
36
+ delete_if_exists(project_path)
37
+ else
38
+ puts "- Skipping existing role '#{path}' (use --force option to overwrite it)"
39
+ return
40
+ end
41
+ end
42
+ puts "+ Adding role '#{path}'"
43
+ FileUtils.mkdir_p(dirname)
44
+ FileUtils.send(file_utils_method, populate_ansible_path, project_path)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ module AnsibleUtils
2
+ module PlaybookHelpers
3
+
4
+ def config_file_path
5
+ @config_file_path ||= File.join(ENV.fetch('HOME'), '.config', 'ansible-utils', 'config.yml')
6
+ end
7
+
8
+ def delete_if_exists path
9
+ FileUtils.remove_entry(path, true)
10
+ end
11
+
12
+ def paths
13
+ @paths ||= roles.map{|role| role['role'] }
14
+ end
15
+
16
+ def roles
17
+ playbook['roles']
18
+ end
19
+
20
+ def project_folder
21
+ @project_folder ||= File.dirname(playbook_path)
22
+ end
23
+
24
+ def generic_roles_folder
25
+ begin
26
+ if File.file?(config_file_path)
27
+ return YAML.load(File.read(config_file_path))['generic_roles_path']
28
+ else
29
+ raise "Missing config file at #{config_file_path}. Run `ansible-utils config` for proper setup"
30
+ end
31
+ rescue Psych::SyntaxError
32
+ raise "Error reading config file at #{config_file_path}"
33
+ end
34
+ end
35
+
36
+ def playbook
37
+ @playbook ||= YAML.load_file(playbook_path).first
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module AnsibleUtils
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ansible-utils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Víctor Martín
8
+ - Fernando Blat
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-01-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: commander
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '4.5'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '4.5'
28
+ - !ruby/object:Gem::Dependency
29
+ name: bundler
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.1'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.1'
42
+ - !ruby/object:Gem::Dependency
43
+ name: pry
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '13.0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '13.0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.4'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.4'
84
+ - !ruby/object:Gem::Dependency
85
+ name: rubocop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.59.2
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: 0.59.2
98
+ description:
99
+ email:
100
+ - victor@populate.tools
101
+ - fernando@populate.tools
102
+ executables:
103
+ - ansible-utils
104
+ extensions: []
105
+ extra_rdoc_files: []
106
+ files:
107
+ - ".gitignore"
108
+ - CODE_OF_CONDUCT.md
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE
112
+ - README.md
113
+ - ansible_utils.gemspec
114
+ - bin/ansible-utils
115
+ - lib/ansible_utils/dependency_manager.rb
116
+ - lib/ansible_utils/playbook_helpers.rb
117
+ - lib/ansible_utils/version.rb
118
+ homepage: https://github.com/PopulateTools/ansible-utils
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: 2.7.0
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubygems_version: 3.2.3
138
+ signing_key:
139
+ specification_version: 4
140
+ summary: PopulateTools Ansible Utils
141
+ test_files: []