smart_proxy_ansible_director 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11b4f80f48a4372c163be6a36eaac462054a9b8faeeecdf19bd8c1de4b3aae05
4
- data.tar.gz: 0cc24d6656aacfebc1bc1be8a8b39e741faaf467f90b0a5055ba5a6589d6b8bb
3
+ metadata.gz: 8b4c354edd008b22c1a7c3bb81961c43c0159083c8605b06c04f7a1d85bd5c32
4
+ data.tar.gz: edf3d06edeef438c682173531b0ac2e29911803afc448c2bcca3f1f5b1517090
5
5
  SHA512:
6
- metadata.gz: 710655ed3b2ee6b8b7c553da0ff6a3e358e99e2b103bd1655b992af6ebfc4b8d3a27e8aa0230c454ed77f3a73896a3f335d3645e680505d6e5bc14a848e1d87e
7
- data.tar.gz: a37793192570e852c6587350dc6216b03bfe50934122e67a2fc8e871b6546f9134729e0d7097a9104ea538a4662b9c08fb50dec1c6a41c4cbb7b534284064653
6
+ metadata.gz: 7522c49d2d8ff5aac7499681d8321d1fdbe6f879df564da7a1cf5a53d04a20dd8ceddb1a7817e4ff65fe5e704039c75f16072e1cf460bd7d30a2af28f370cbb4
7
+ data.tar.gz: e41d6d20ccf4729d5550b6909b7bf5f4151171f2999684712a87db978dd7c27a1f2f5621efbe14659a7d02647599a2e52a41c8c4798982ef98d25fcd283fcdd3
@@ -3,6 +3,7 @@
3
3
  require_relative '../build_execution_environment'
4
4
  require_relative '../push_execution_environment'
5
5
  require_relative '../../helpers/execution_environment_helpers'
6
+ require_relative '../../runners/meta_runner'
6
7
  require 'smart_proxy_dynflow/callback'
7
8
 
8
9
  module Proxy
@@ -10,40 +11,40 @@ module Proxy
10
11
  module Actions
11
12
  module Meta
12
13
  class RunPlaybook < ::Proxy::Dynflow::Action::Runner
13
- def plan(args)
14
- execution_environment = args['execution_environment']
14
+ def initiate_runner
15
+ execution_environment = input['execution_environment']
15
16
 
16
17
  ee_id = execution_environment['id']
17
18
  ee_registry_url = execution_environment['registry_url']
18
19
  ee_ansible_core_version = execution_environment['ansible_core_version']
19
20
 
20
21
 
21
- inventory = args['inventory']
22
- playbook = args['playbook']
23
- variables = args['variables']
22
+ inventory = input['inventory']
23
+ playbook = input['playbook']
24
+ variables = input['variables'].to_hash
24
25
  content = ::Proxy::AnsibleDirector::Helpers::ExecutionEnvironmentHelpers.format_content(
25
- args['content']
26
+ input['content']
26
27
  )
27
28
 
28
- sequence do
29
- plan_action ::Proxy::AnsibleDirector::Actions::BuildExecutionEnvironment, {
30
- ee_id: ee_id,
31
- ee_base_image_url: ee_registry_url,
32
- ee_built_image_tag: @caller_execution_plan_id,
33
- ee_ansible_core_version: ee_ansible_core_version,
34
- ee_formatted_content: content,
35
- is_base_image: false
29
+ ::Proxy::AnsibleDirector::Runners::MetaRunner.new(
30
+ {
31
+ build_ee_input: {
32
+ ee_id: ee_id,
33
+ ee_base_image_url: ee_registry_url,
34
+ ee_built_image_tag: @caller_execution_plan_id,
35
+ ee_ansible_core_version: ee_ansible_core_version,
36
+ ee_formatted_content: content,
37
+ is_base_image: false
38
+ },
39
+ run_ansible_input: {
40
+ inventory: inventory,
41
+ playbook: playbook,
42
+ variables: variables,
43
+ execution_environment: ee_registry_url.sub("latest",
44
+ @caller_execution_plan_id)
45
+ }
36
46
  }
37
- run_ansible_action = plan_action ::Proxy::AnsibleDirector::Actions::RunAnsibleNavigator, {
38
- inventory: inventory,
39
- playbook: playbook,
40
- variables: variables,
41
- execution_environment: ee_registry_url.sub!("latest", @caller_execution_plan_id)
42
- }
43
- plan_action ::Proxy::Dynflow::Callback::Action,
44
- args[:callback],
45
- run_ansible_action.output
46
- end
47
+ )
47
48
  end
48
49
  end
49
50
  end
@@ -11,9 +11,9 @@ module Proxy
11
11
 
12
12
  content_units.each do |content_unit|
13
13
  formatted_unit = {
14
- name: content_unit['identifier'],
15
- version: content_unit['version'],
16
- source: content_unit['source']
14
+ 'name' => content_unit['identifier'],
15
+ 'version' => content_unit['version'],
16
+ 'source' => content_unit['source']
17
17
  }
18
18
 
19
19
  case content_unit['type']
@@ -24,8 +24,8 @@ module Proxy
24
24
  end
25
25
  end
26
26
  {
27
- collections: collections.length.positive? ? collections : nil,
28
- roles: roles.length.positive? ? roles : nil
27
+ 'collections' => collections.length.positive? ? collections : nil,
28
+ 'roles' => roles.length.positive? ? roles : nil
29
29
  }.compact!
30
30
  end
31
31
 
@@ -8,6 +8,8 @@ module Proxy
8
8
  class AnsibleBuilderRunner < ::Proxy::Dynflow::Runner::Base
9
9
  include ::Proxy::Dynflow::Runner::ProcessManagerCommand
10
10
 
11
+ attr_reader :continuous_output, :exit_status
12
+
11
13
  # ansible_builder_input
12
14
  # {
13
15
  # ee_id: ee_id,
@@ -33,6 +35,15 @@ module Proxy
33
35
 
34
36
  def start
35
37
  ee_content = @ee_formatted_content.to_hash
38
+ ee_content.transform_values! do |value|
39
+ value.map do |cuv|
40
+ {
41
+ 'name' => cuv['name'],
42
+ 'source' => cuv['source'],
43
+ 'version' => cuv['version']
44
+ }.compact
45
+ end
46
+ end
36
47
 
37
48
  if @is_base_image
38
49
  ee_content.merge!(
@@ -10,6 +10,8 @@ module Proxy
10
10
  class AnsibleNavigatorRunner < ::Proxy::Dynflow::Runner::Base
11
11
  include ::Proxy::Dynflow::Runner::ProcessManagerCommand
12
12
 
13
+ attr_reader :continuous_output, :exit_status
14
+
13
15
  def initialize(ansible_input, suspended_action: nil)
14
16
  super suspended_action: suspended_action
15
17
  @inventory = ::Proxy::AnsibleDirector::Helpers::AnsibleNavigatorHelpers.reserialize_inventory(ansible_input[:inventory])
@@ -28,6 +30,8 @@ module Proxy
28
30
 
29
31
  def start
30
32
  # TODO: Find a way to request the auth token programmatically
33
+ proxy_ssh_key_path = ::Proxy::RemoteExecution::Ssh::Plugin.settings[:ssh_identity_key_file]
34
+ proxy_ssh_key_mount_path = "/runner/.ssh/#{File.basename(proxy_ssh_key_path)}"
31
35
  cmd = <<~CMD
32
36
  echo "Running in #{@runner_workdir}"
33
37
 
@@ -72,8 +76,8 @@ module Proxy
72
76
  dest: /run/secrets/foreman_ssl_key
73
77
  - src: #{File.join(Dir.pwd, Proxy::SETTINGS.foreman_ssl_ca)}
74
78
  dest: /run/secrets/foreman_ssl_verify
75
- - src: /usr/share/foreman-proxy/.ssh/id_rsa_foreman_proxy
76
- dest: /runner/.ssh/id_rsa_foreman_proxy
79
+ - src: #{proxy_ssh_key_path}
80
+ dest: #{proxy_ssh_key_mount_path}
77
81
  logging:
78
82
  level: debug
79
83
  file: #{@runner_workdir}/ansible-navigator.log
@@ -81,7 +85,7 @@ module Proxy
81
85
  EOF
82
86
 
83
87
  cd #{@runner_workdir}/
84
- ansible-navigator run --mode stdout
88
+ ansible-navigator run --private-key=#{proxy_ssh_key_mount_path}
85
89
  CMD
86
90
  initialize_command('bash', '-c', cmd)
87
91
  end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../runners'
4
+
5
+ module Proxy
6
+ module AnsibleDirector
7
+ module Runners
8
+ class MetaRunner < ::Proxy::Dynflow::Runner::Base
9
+ PHASES = [
10
+ { id: :build_ee, title: 'Building execution environment', runner_class: AnsibleBuilderRunner,
11
+ runner_input_key: :build_ee_input },
12
+ { id: :run_ansible, title: 'Running Ansible', runner_class: AnsibleNavigatorRunner,
13
+ runner_input_key: :run_ansible_input }
14
+ ].freeze
15
+
16
+ def initialize(input, suspended_action: nil)
17
+ super(suspended_action: suspended_action)
18
+ @input = input
19
+ @phase_index = 0
20
+ @current_runner = nil
21
+ end
22
+
23
+ def start
24
+ transition_to_phase(@phase_index)
25
+ end
26
+
27
+ def refresh
28
+ return unless @current_runner
29
+
30
+ @current_runner.refresh
31
+
32
+ @continuous_output.raw_outputs.concat(@current_runner.continuous_output.raw_outputs)
33
+ @current_runner.continuous_output.raw_outputs.clear
34
+
35
+ return unless @current_runner.exit_status
36
+
37
+ if @current_runner.exit_status != 0
38
+ publish_exit_status(@current_runner.exit_status)
39
+ else
40
+ transition_to_next_phase
41
+ end
42
+ end
43
+
44
+ def kill
45
+ @current_runner&.kill
46
+ end
47
+
48
+ def close
49
+ @current_runner&.close
50
+ end
51
+
52
+ private
53
+
54
+ def transition_to_phase(index)
55
+ phase_info = PHASES[index]
56
+
57
+ @phase_index = index
58
+ runner_class = phase_info[:runner_class]
59
+ runner_input = @input[phase_info[:runner_input_key]]
60
+
61
+ @continuous_output.add_output(
62
+ "START: Phase #{phase_info[:id]} (#{index + 1} / #{PHASES.length}): #{phase_info[:title]}\n"
63
+ )
64
+
65
+ @current_runner = runner_class.new(runner_input, suspended_action: @suspended_action)
66
+ @current_runner.start
67
+ end
68
+
69
+ def transition_to_next_phase
70
+ phase_info = PHASES[@phase_index]
71
+ @continuous_output.add_output(
72
+ "END: Phase #{phase_info[:id]}: #{phase_info[:title]}\n"
73
+ )
74
+
75
+ if @phase_index + 1 < PHASES.length
76
+ @phase_index += 1
77
+ transition_to_phase(@phase_index)
78
+ else
79
+ publish_exit_status(0)
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Proxy
4
4
  module AnsibleDirector
5
- VERSION = '0.5.0'
5
+ VERSION = '0.6.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_ansible_director
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
@@ -29,6 +29,26 @@ dependencies:
29
29
  - - "<"
30
30
  - !ruby/object:Gem::Version
31
31
  version: 2.0.0
32
+ - !ruby/object:Gem::Dependency
33
+ name: smart_proxy_remote_execution_ssh
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: 0.11.6
39
+ - - "<"
40
+ - !ruby/object:Gem::Version
41
+ version: 2.0.0
42
+ type: :runtime
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: 0.11.6
49
+ - - "<"
50
+ - !ruby/object:Gem::Version
51
+ version: 2.0.0
32
52
  - !ruby/object:Gem::Dependency
33
53
  name: mocha
34
54
  requirement: !ruby/object:Gem::Requirement
@@ -103,6 +123,7 @@ files:
103
123
  - lib/smart_proxy_ansible_director/runners.rb
104
124
  - lib/smart_proxy_ansible_director/runners/ansible_builder_runner.rb
105
125
  - lib/smart_proxy_ansible_director/runners/ansible_navigator_runner.rb
126
+ - lib/smart_proxy_ansible_director/runners/meta_runner.rb
106
127
  - lib/smart_proxy_ansible_director/runners/podman_pull_runner.rb
107
128
  - lib/smart_proxy_ansible_director/runners/podman_push_runner.rb
108
129
  - lib/smart_proxy_ansible_director/version.rb
@@ -128,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
149
  - !ruby/object:Gem::Version
129
150
  version: '0'
130
151
  requirements: []
131
- rubygems_version: 4.0.6
152
+ rubygems_version: 4.0.10
132
153
  specification_version: 4
133
154
  summary: Smart Proxy plugin to integrate Ansible Director with Foreman
134
155
  test_files: []