kitchen-yansible-pusher 0.2.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa8a79886e6402a3e4a5c8c788ac05e7e2c1e7e156b0f112d8512055b30bc595
4
- data.tar.gz: 7bc8189cd68321d3f9819caa02d0f8cc90800b8853043f8120e61d3345e97967
3
+ metadata.gz: 25785faaa8f4cf4b1e458db922a180ffcbfc3e90bf1a29be3cc8e7d6ba009a56
4
+ data.tar.gz: 399e8268e43f34498c1d14d14d0268d3e621f4411d01b2fa0203494af39aa248
5
5
  SHA512:
6
- metadata.gz: 67185ace3c508dc785f86a40bfe4868b1fd735549a3ac25a001fe2b06eda89354afad72296a439661d610156ad9e094fe63ab4e9b06e196943fe7c1542cff650
7
- data.tar.gz: 9ce899f9b3803df41c2a097bd8fdbe395769a2379d4dc395a0150650eb3857397594a011734c578f72de3917c22c2eb9f87910fb7f9a4f7a8aa123e9225c7461
6
+ metadata.gz: 43ae3f45fadb4ca31cbdf783c19d7c49ae7241a27118a3387ae8ef6eefc911b32433a1632b0afd75d27638b6b0f8be59c30c40e243f944a7a509333bf170cffd
7
+ data.tar.gz: 74e5bfe68ee3c9a6335b588751afed8e1ebfb5b32d241e0601ee8aef573048b68e0c93412a7b6e8a2a31f8adca9306d79b1e6784f0a578e2b9e0f4038aebb64f
data/CHANGELOG.md CHANGED
@@ -1,5 +1,61 @@
1
- ## [Unreleased]
1
+ # Changelog
2
2
 
3
- ## [0.1.0] - 2024-08-29
3
+ ## [v0.3.0](https://github.com/jmtx1020/kitchen-yansible-pusher/tree/v0.3.0) (2024-09-04)
4
4
 
5
- - Initial release
5
+ [Full Changelog](https://github.com/jmtx1020/kitchen-yansible-pusher/compare/v0.2.0...v0.3.0)
6
+
7
+ **Merged pull requests:**
8
+
9
+ - added chocolatey to reqs [\#13](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/13) ([jmtx1020](https://github.com/jmtx1020))
10
+ - add winrm support [\#12](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/12) ([jmtx1020](https://github.com/jmtx1020))
11
+ - added CHANGELOG update action [\#11](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/11) ([jmtx1020](https://github.com/jmtx1020))
12
+
13
+ ## [v0.2.0](https://github.com/jmtx1020/kitchen-yansible-pusher/tree/v0.2.0) (2024-08-31)
14
+
15
+ [Full Changelog](https://github.com/jmtx1020/kitchen-yansible-pusher/compare/v0.1.3...v0.2.0)
16
+
17
+ **Merged pull requests:**
18
+
19
+ - updated gem version [\#10](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/10) ([jmtx1020](https://github.com/jmtx1020))
20
+ - Feature: Added support for extra flags [\#9](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/9) ([jmtx1020](https://github.com/jmtx1020))
21
+ - rename `extra_vars` to `env_vars` since it's for setting environment variables [\#8](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/8) ([jmtx1020](https://github.com/jmtx1020))
22
+
23
+ ## [v0.1.3](https://github.com/jmtx1020/kitchen-yansible-pusher/tree/v0.1.3) (2024-08-31)
24
+
25
+ [Full Changelog](https://github.com/jmtx1020/kitchen-yansible-pusher/compare/v0.1.2...v0.1.3)
26
+
27
+ **Merged pull requests:**
28
+
29
+ - fixed issue where user had to submit a vault file, updated version, enable fix branches in integration tests [\#7](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/7) ([jmtx1020](https://github.com/jmtx1020))
30
+
31
+ ## [v0.1.2](https://github.com/jmtx1020/kitchen-yansible-pusher/tree/v0.1.2) (2024-08-31)
32
+
33
+ [Full Changelog](https://github.com/jmtx1020/kitchen-yansible-pusher/compare/v0.1.1...v0.1.2)
34
+
35
+ **Merged pull requests:**
36
+
37
+ - bumping version [\#6](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/6) ([jmtx1020](https://github.com/jmtx1020))
38
+
39
+ ## [v0.1.1](https://github.com/jmtx1020/kitchen-yansible-pusher/tree/v0.1.1) (2024-08-31)
40
+
41
+ [Full Changelog](https://github.com/jmtx1020/kitchen-yansible-pusher/compare/v0.1.0...v0.1.1)
42
+
43
+ ## [v0.1.0](https://github.com/jmtx1020/kitchen-yansible-pusher/tree/v0.1.0) (2024-08-31)
44
+
45
+ [Full Changelog](https://github.com/jmtx1020/kitchen-yansible-pusher/compare/v0.0.1pre...v0.1.0)
46
+
47
+ **Merged pull requests:**
48
+
49
+ - added allowed host push urls [\#5](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/5) ([jmtx1020](https://github.com/jmtx1020))
50
+ - added better names, and release pipeline to rubygems [\#4](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/4) ([jmtx1020](https://github.com/jmtx1020))
51
+ - Added Integration Tests [\#3](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/3) ([jmtx1020](https://github.com/jmtx1020))
52
+ - additional-ruby-versions [\#2](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/2) ([jmtx1020](https://github.com/jmtx1020))
53
+ - added github actions release pipeline [\#1](https://github.com/jmtx1020/kitchen-yansible-pusher/pull/1) ([jmtx1020](https://github.com/jmtx1020))
54
+
55
+ ## [v0.0.1pre](https://github.com/jmtx1020/kitchen-yansible-pusher/tree/v0.0.1pre) (2024-08-30)
56
+
57
+ [Full Changelog](https://github.com/jmtx1020/kitchen-yansible-pusher/compare/1bf46ae6cbbff66f85fd2d3857271c44af727b56...v0.0.1pre)
58
+
59
+
60
+
61
+ \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
data/README.md CHANGED
@@ -68,6 +68,46 @@ suites:
68
68
 
69
69
  ```
70
70
 
71
+ ### Usage on Windows - Requirements
72
+
73
+ To use this gem and with a Windows target you need to install [PyWinRM](https://pypi.org/project/pywinrm/) as it is not part of the standard Ansible core distributed when you install through any methods.
74
+
75
+ ```
76
+ pip install pywinrm
77
+ ```
78
+
79
+ This error is known to occur when using the WinRM gem on Mac OS hosts due to the way Python forking works.
80
+
81
+ ```
82
+ objc[78682]: +[__NSCFConstantString initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.
83
+ ```
84
+
85
+ The solution is to run this command and then you should be able to run your role successfully.
86
+
87
+ ```
88
+ export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
89
+ ```
90
+
91
+ ### Windows Usage - Configuration
92
+
93
+ This provisoner infers the settings needed to connect to the box using the connection data from the instance, however if you need to overwrite any of these settings they are overwritable by specifying these values.
94
+
95
+ ```yaml
96
+ provisioner:
97
+ name: yansible_pusher
98
+ winrm:
99
+ host: ""
100
+ port: 1234
101
+ user: username1
102
+ password: SuperSecurePassword!
103
+ connection: 'winrm'
104
+ server_cert_validation: 'ignore'
105
+ transport: 'ssl'
106
+ scheme: 'http'
107
+ ```
108
+
109
+ More information about these settings can be found [here](https://docs.ansible.com/ansible/latest/os_guide/windows_winrm.html).
110
+
71
111
  ## Contributing
72
112
 
73
113
  Bug reports and pull requests are welcome on GitHub at https://github.com/jmtx1020/kitchen-yansible-pusher.
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'kitchen/provisioner/base'
4
+ require 'kitchen/errors'
4
5
  require_relative '../yansible/pusher/version'
5
6
  require 'yaml'
6
7
 
@@ -35,6 +36,7 @@ module Kitchen
35
36
  default_config :vault_password_file, nil
36
37
  default_config :username, nil
37
38
  default_config :private_key, nil
39
+ default_config :windows_config, nil
38
40
 
39
41
  attr_reader :sandbox_path
40
42
 
@@ -62,6 +64,7 @@ module Kitchen
62
64
  ensure
63
65
  cleanup_sandbox
64
66
  end
67
+ ensure_windows_exit_code if windows_instance?
65
68
  end
66
69
 
67
70
  private
@@ -70,6 +73,7 @@ module Kitchen
70
73
  command = build_ansible_command
71
74
  info("Running Ansible Command: #{command}")
72
75
  system(command)
76
+ raise Kitchen::ActionFailed, 'Ansible playbook execution failed' unless $?.success?
73
77
  end
74
78
 
75
79
  def create_inventory
@@ -89,6 +93,14 @@ module Kitchen
89
93
  end
90
94
 
91
95
  def build_host_config(state)
96
+ if windows_instance?
97
+ build_windows_config(state)
98
+ else
99
+ build_linux_config(state)
100
+ end
101
+ end
102
+
103
+ def build_linux_config(state)
92
104
  {
93
105
  'ansible_host' => state[:hostname],
94
106
  'ansible_port' => state[:port],
@@ -96,6 +108,28 @@ module Kitchen
96
108
  }
97
109
  end
98
110
 
111
+ def build_windows_config(state)
112
+ uri = URI(state[:endpoint])
113
+ defaults = default_windows_config(state, uri)
114
+ user_windows_config(defaults)
115
+ end
116
+
117
+ def user_windows_config(defaults)
118
+ user_config = (config[:winrm_config] || {}).transform_keys { |key| "ansible_#{key}" }
119
+ defaults.merge(user_config.compact)
120
+ end
121
+
122
+ def default_windows_config(state, uri)
123
+ { 'ansible_host' => uri.host,
124
+ 'ansible_port' => state[:port] || uri.port,
125
+ 'ansible_user' => state[:user],
126
+ 'ansible_password' => state[:password],
127
+ 'ansible_connection' => 'winrm',
128
+ 'ansible_winrm_server_cert_validation' => 'ignore',
129
+ 'ansible_winrm_transport' => 'ssl',
130
+ 'ansible_winrm_scheme' => uri.scheme }
131
+ end
132
+
99
133
  def write_inventory_file(inventory)
100
134
  inventory_file = File.join(sandbox_path, 'inventory.yml')
101
135
  File.write(inventory_file, inventory.to_yaml)
@@ -134,7 +168,7 @@ module Kitchen
134
168
  end
135
169
 
136
170
  def ansible_extra_flags(cmd)
137
- cmd << "#{config[:extra_flags].join(" ")}" unless config[:extra_flags].empty?
171
+ cmd << config[:extra_flags].join(' ') unless config[:extra_flags].empty?
138
172
  cmd
139
173
  end
140
174
 
@@ -153,7 +187,7 @@ module Kitchen
153
187
  cmd << "--private-key #{config[:private_key]}"
154
188
  else
155
189
  state = instance.transport.instance_variable_get(:@connection_options)
156
- cmd << "--private-key #{state[:keys][0]}"
190
+ cmd << "--private-key #{state[:keys][0]}" if state.key?(:keys)
157
191
  end
158
192
  cmd
159
193
  end
@@ -165,6 +199,7 @@ module Kitchen
165
199
 
166
200
  def ansible_verbosity(cmd)
167
201
  cmd << "-#{'v' * config[:verbosity]}" if config[:verbosity] >= 1
202
+ cmd
168
203
  end
169
204
 
170
205
  def create_sandbox
@@ -186,6 +221,25 @@ module Kitchen
186
221
  error("Failed to clean up sandbox: #{e.message}")
187
222
  raise
188
223
  end
224
+
225
+ def windows_instance?
226
+ instance.transport.instance_variable_get(:@connection_options).key?(:endpoint)
227
+ end
228
+
229
+ # Ensures proper exit code handling for Windows instances in Test Kitchen.
230
+ #
231
+ # @return [String] A PowerShell command string to be executed on the remote Windows system.
232
+ #
233
+ # This method is only called for Windows instances. It returns a PowerShell command that:
234
+ # 1. Outputs the status of the last command ($?)
235
+ # 2. Exits with 0 if the last command succeeded, or 1 if it failed
236
+ #
237
+ # This approach addresses a specific issue with Test Kitchen's WinRM transport,
238
+ # where it expects a command string to execute rather than a boolean result.
239
+ # It ensures that the correct exit code is returned to Test Kitchen.
240
+ def ensure_windows_exit_code
241
+ '$?; if($?) { exit 0 } else { exit 1 }'
242
+ end
189
243
  end
190
244
  end
191
245
  end
@@ -3,7 +3,7 @@
3
3
  module Kitchen
4
4
  module Yansible
5
5
  module Pusher
6
- VERSION = "0.2.0"
6
+ VERSION = "0.3.1"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kitchen-yansible-pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jose M. Tobar
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-08-31 00:00:00.000000000 Z
11
+ date: 2024-09-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A modern & minimalistic Ansible provisioner for Test Kitchen.
14
14
  email:
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
- rubygems_version: 3.5.11
52
+ rubygems_version: 3.5.16
53
53
  signing_key:
54
54
  specification_version: 4
55
55
  summary: A modern & minimalistic Ansible provisioner for Test Kitchen.