Skip to content

Commit b9bb68f

Browse files
authored
Fixes #35455 - Generate an environment file for ansible
This file will be sourced by smart_proxy_ansible before it starts ansible-runner. This way, people can tweak their own ansible.cfg, but the values we need will have a higher priority.
1 parent 5c9db94 commit b9bb68f

File tree

7 files changed

+43
-60
lines changed

7 files changed

+43
-60
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Part of the Foreman installer: <https://github.com/theforeman/foreman-installer>
2828
| 2.x | 1.5 - 1.10 | |
2929
| 1.x | 1.4 and older | |
3030

31-
* 24.x dropped management of ansible-runner repository, ansible-runner is now in the Foreman plugin repository. This requires Foreman 3.5.
31+
* 24.x dropped management of ansible-runner repository, ansible-runner is now in the Foreman plugin repository. This requires Foreman 3.5. Ansible configuration is now done by deploying a file with environment variables that is sourced by smart_proxy_ansible and therefore is incompatible with versions older than 3.5.0.
3232
* 23.x dropped EL7 support. 3.1 and newer work on EL8.
3333
* 22.x renamed foreman_proxy::plugin::remote_execution::ssh to foreman_proxy::plugin::remote_execution::script as the feature within the plugin has changed from SSH to Script.
3434
* 20.x started to register as a Smart Proxy host. This requires Foreman 3.1. When using an older Foreman, set `$register_in_foreman` to false. This does require manual registration then.

manifests/plugin/ansible.pp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
# of the key, which is not possible from non-interactive
2121
# environments like Foreman Remote Execution or cron
2222
#
23-
# $stdout_callback:: Ansible's stdout_callback setting
24-
#
2523
# $roles_path:: Paths where we look for ansible roles.
2624
#
2725
# $ssh_args:: The ssh_args parameter in ansible.cfg under [ssh_connection]
@@ -40,7 +38,6 @@
4038
Stdlib::Absolutepath $ansible_dir = $foreman_proxy::plugin::ansible::params::ansible_dir,
4139
Optional[Stdlib::Absolutepath] $working_dir = $foreman_proxy::plugin::ansible::params::working_dir,
4240
Boolean $host_key_checking = $foreman_proxy::plugin::ansible::params::host_key_checking,
43-
String $stdout_callback = $foreman_proxy::plugin::ansible::params::stdout_callback,
4441
Array[Stdlib::Absolutepath] $roles_path = $foreman_proxy::plugin::ansible::params::roles_path,
4542
String $ssh_args = $foreman_proxy::plugin::ansible::params::ssh_args,
4643
Boolean $install_runner = $foreman_proxy::plugin::ansible::params::install_runner,
@@ -53,17 +50,13 @@
5350
$foreman_ssl_key = pick($foreman_proxy::foreman_ssl_key, $foreman_proxy::ssl_key)
5451
$foreman_ssl_ca = pick($foreman_proxy::foreman_ssl_ca, $foreman_proxy::ssl_ca)
5552

56-
file { "${foreman_proxy::config_dir}/ansible.cfg":
53+
file { "${foreman_proxy::config_dir}/ansible.env":
5754
ensure => file,
58-
content => template('foreman_proxy/plugin/ansible.cfg.erb'),
55+
content => template('foreman_proxy/plugin/ansible.env.erb'),
5956
owner => 'root',
6057
group => $foreman_proxy::user,
6158
mode => '0640',
6259
}
63-
~> file { "${foreman_proxy::dir}/.ansible.cfg":
64-
ensure => link,
65-
target => "${foreman_proxy::config_dir}/ansible.cfg",
66-
}
6760

6861
include foreman_proxy::plugin::dynflow
6962
if $install_runner {

manifests/plugin/ansible/params.pp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
$ansible_dir = $foreman_proxy::params::dir
99
$working_dir = '/tmp'
1010
$host_key_checking = false
11-
$stdout_callback = 'yaml'
1211
$roles_path = ['/etc/ansible/roles', '/usr/share/ansible/roles']
1312
$ssh_args = '-o ProxyCommand=none -C -o ControlMaster=auto -o ControlPersist=60s'
1413
$install_runner = true

spec/classes/foreman_proxy__plugin__ansible_spec.rb

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,20 @@
2929
with_content(%r{:ansible_dir: /usr/share/foreman-proxy})
3030
end
3131

32-
it 'should configure ansible.cfg' do
32+
it 'should configure ansible.env' do
3333
callback = facts[:os]['family'] == 'RedHat' ? 'theforeman.foreman.foreman' : 'foreman'
34-
verify_exact_contents(catalogue, '/etc/foreman-proxy/ansible.cfg', [
35-
'[defaults]',
36-
"callback_whitelist = #{callback}",
37-
'local_tmp = /tmp',
38-
'host_key_checking = False',
39-
'stdout_callback = yaml',
40-
'[callback_foreman]',
41-
'url = https://foo.example.com',
42-
'ssl_key = /etc/puppetlabs/puppet/ssl/private_keys/foo.example.com.pem',
43-
'ssl_cert = /etc/puppetlabs/puppet/ssl/certs/foo.example.com.pem',
44-
'verify_certs = /etc/puppetlabs/puppet/ssl/certs/ca.pem',
45-
'roles_path = /etc/ansible/roles:/usr/share/ansible/roles',
46-
'collections_paths = /etc/ansible/collections:/usr/share/ansible/collections',
47-
'[ssh_connection]',
48-
'ssh_args = -o ProxyCommand=none -C -o ControlMaster=auto -o ControlPersist=60s',
34+
verify_exact_contents(catalogue, '/etc/foreman-proxy/ansible.env', [
35+
"export ANSIBLE_CALLBACK_WHITELIST=\"#{callback}\"",
36+
"export ANSIBLE_CALLBACKS_ENABLED=\"#{callback}\"",
37+
'export ANSIBLE_LOCAL_TEMP="/tmp"',
38+
'export ANSIBLE_HOST_KEY_CHECKING="False"',
39+
'export ANSIBLE_ROLES_PATH="/etc/ansible/roles:/usr/share/ansible/roles"',
40+
'export ANSIBLE_COLLECTIONS_PATHS="/etc/ansible/collections:/usr/share/ansible/collections"',
41+
'export FOREMAN_URL="https://foo.example.com"',
42+
'export FOREMAN_SSL_KEY="/etc/puppetlabs/puppet/ssl/private_keys/foo.example.com.pem"',
43+
'export FOREMAN_SSL_CERT="/etc/puppetlabs/puppet/ssl/certs/foo.example.com.pem"',
44+
'export FOREMAN_SSL_VERIFY="/etc/puppetlabs/puppet/ssl/certs/ca.pem"',
45+
'export ANSIBLE_SSH_ARGS="-o ProxyCommand=none -C -o ControlMaster=auto -o ControlPersist=60s"',
4946
])
5047
end
5148
end
@@ -57,7 +54,6 @@
5754
ansible_dir: '/etc/ansible-test',
5855
working_dir: '/tmp/ansible',
5956
host_key_checking: true,
60-
stdout_callback: 'debug',
6157
}
6258
end
6359

@@ -79,23 +75,20 @@
7975
with_content(%r{:working_dir: /tmp/ansible})
8076
end
8177

82-
it 'should configure ansible.cfg' do
78+
it 'should configure ansible.env' do
8379
callback = facts[:os]['family'] == 'RedHat' ? 'theforeman.foreman.foreman' : 'foreman'
84-
verify_exact_contents(catalogue, '/etc/foreman-proxy/ansible.cfg', [
85-
'[defaults]',
86-
"callback_whitelist = #{callback}",
87-
'local_tmp = /tmp/ansible',
88-
'host_key_checking = True',
89-
'stdout_callback = debug',
90-
'[callback_foreman]',
91-
'url = https://foo.example.com',
92-
'ssl_key = /etc/puppetlabs/puppet/ssl/private_keys/foo.example.com.pem',
93-
'ssl_cert = /etc/puppetlabs/puppet/ssl/certs/foo.example.com.pem',
94-
'verify_certs = /etc/puppetlabs/puppet/ssl/certs/ca.pem',
95-
'roles_path = /etc/ansible/roles:/usr/share/ansible/roles',
96-
'collections_paths = /etc/ansible/collections:/usr/share/ansible/collections',
97-
'[ssh_connection]',
98-
'ssh_args = -o ProxyCommand=none -C -o ControlMaster=auto -o ControlPersist=60s',
80+
verify_exact_contents(catalogue, '/etc/foreman-proxy/ansible.env', [
81+
"export ANSIBLE_CALLBACK_WHITELIST=\"#{callback}\"",
82+
"export ANSIBLE_CALLBACKS_ENABLED=\"#{callback}\"",
83+
'export ANSIBLE_LOCAL_TEMP="/tmp/ansible"',
84+
'export ANSIBLE_HOST_KEY_CHECKING="True"',
85+
'export ANSIBLE_ROLES_PATH="/etc/ansible/roles:/usr/share/ansible/roles"',
86+
'export ANSIBLE_COLLECTIONS_PATHS="/etc/ansible/collections:/usr/share/ansible/collections"',
87+
'export FOREMAN_URL="https://foo.example.com"',
88+
'export FOREMAN_SSL_KEY="/etc/puppetlabs/puppet/ssl/private_keys/foo.example.com.pem"',
89+
'export FOREMAN_SSL_CERT="/etc/puppetlabs/puppet/ssl/certs/foo.example.com.pem"',
90+
'export FOREMAN_SSL_VERIFY="/etc/puppetlabs/puppet/ssl/certs/ca.pem"',
91+
'export ANSIBLE_SSH_ARGS="-o ProxyCommand=none -C -o ControlMaster=auto -o ControlPersist=60s"',
9992
])
10093
end
10194
end

templates/plugin/ansible.cfg.erb

Lines changed: 0 additions & 16 deletions
This file was deleted.

templates/plugin/ansible.env.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export ANSIBLE_CALLBACK_WHITELIST="<%= @callback %>"
2+
export ANSIBLE_CALLBACKS_ENABLED="<%= @callback %>"
3+
export ANSIBLE_LOCAL_TEMP="<%= @working_dir %>"
4+
export ANSIBLE_HOST_KEY_CHECKING="<%= @host_key_checking ? 'True' : 'False' %>"
5+
export ANSIBLE_ROLES_PATH="<%= @roles_path.join(':') %>"
6+
export ANSIBLE_COLLECTIONS_PATHS="<%= @collections_paths.join(':') %>"
7+
8+
export FOREMAN_URL="<%= @foreman_url %>"
9+
export FOREMAN_SSL_CERT="<%= @foreman_ssl_cert %>"
10+
export FOREMAN_SSL_KEY="<%= @foreman_ssl_key %>"
11+
export FOREMAN_SSL_VERIFY="<%= @foreman_ssl_ca %>"
12+
13+
export ANSIBLE_SSH_ARGS="<%= @ssh_args %>"

templates/plugin/ansible.yml.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
<% else -%>
77
:working_dir: <%= scope.lookupvar("foreman_proxy::plugin::ansible::working_dir") %>
88
<% end -%>
9+
:ansible_environment_file: <%= scope.lookupvar("foreman_proxy::config_dir") %>/ansible.env

0 commit comments

Comments
 (0)