Skip to content
This repository was archived by the owner on Apr 7, 2025. It is now read-only.

Commit 20eefbd

Browse files
syndbgahelal
authored andcommitted
Add environment_vars config (#51)
* Add `environment_vars` config * Update version to `0.10.0` * Add `environment_vars` documentation
1 parent 80d0e7a commit 20eefbd

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: .
33
specs:
4-
kitchen-ansiblepush (0.9.1)
4+
kitchen-ansiblepush (0.10.0)
55
test-kitchen (~> 1.4)
66

77
GEM
@@ -91,4 +91,4 @@ DEPENDENCIES
9191
test-kitchen
9292

9393
BUNDLED WITH
94-
1.16.0
94+
1.17.1

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ provisioner :
7171

7272
## When running on EC2 with Windows and using get-password pass the password as ansible_password variable
7373
pass_transport_password: false
74+
## (optional), if you want to set specific environment variables when running ansible
75+
environment_vars:
76+
PROXMOX_URL: https://example.com:8006
7477
```
7578
## Idempotency test
7679
If you want to check your code is idempotent you can use the idempotency_test. Essentially, this will run Ansible twice and check nothing changed in the second run. If something changed it will list the tasks. Note: If your using Ansible callback in your config this might conflict.

lib/kitchen-ansible/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Kitchen
22
module AnsiblePush
3-
VERSION = '0.9.1'.freeze
3+
VERSION = '0.10.0'.freeze
44
end
55
end

lib/kitchen/provisioner/ansible_push.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class AnsiblePush < Base
5656
default_config :ssh_common_args, nil
5757
default_config :module_path, nil
5858
default_config :pass_transport_password, false
59+
default_config :environment_vars, {}
5960

6061
# For tests disable if not needed
6162
default_config :chef_bootstrap_url, 'https://omnitruck.chef.io/install.sh'
@@ -88,6 +89,12 @@ def conf
8889

8990
raise UserError, "ansible extra_vars is in valid type: #{config[:extra_vars].class} value: #{config[:extra_vars]}" unless extra_vars_is_valid
9091
end
92+
93+
unless config[:environment_vars].is_a?(Hash)
94+
raise UserError,
95+
"ansible environment_vars is not a `Hash` type. Given type: #{config[:environment_vars].class}"
96+
end
97+
9198
info('Ansible push config validated')
9299
@validated_config = config
93100
end
@@ -176,6 +183,11 @@ def command_env
176183
'ANSIBLE_HOST_KEY_CHECKING' => conf[:host_key_checking].to_s
177184
}
178185
@command_env['ANSIBLE_CONFIG'] = conf[:ansible_config] if conf[:ansible_config]
186+
187+
# NOTE: Manually merge to fix keys possibly being Symbol(s)
188+
conf[:environment_vars].each do |key, value|
189+
@command_env[key.to_s] = value
190+
end
179191
@command_env
180192
end
181193

0 commit comments

Comments
 (0)