foreman_acd 0.0.6 → 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 +4 -4
- data/README.md +107 -56
- data/app/controllers/foreman_acd/ansible_playbooks_controller.rb +124 -0
- data/app/controllers/foreman_acd/api/v2/ansible_playbooks_controller.rb +72 -0
- data/app/controllers/foreman_acd/api/v2/app_definitions_controller.rb +2 -2
- data/app/controllers/foreman_acd/api/v2/app_instances_controller.rb +62 -0
- data/app/controllers/foreman_acd/app_definitions_controller.rb +46 -9
- data/app/controllers/foreman_acd/app_instances_controller.rb +96 -90
- data/app/controllers/foreman_acd/concerns/ansible_playbook_parameters.rb +23 -0
- data/app/controllers/foreman_acd/concerns/app_definition_parameters.rb +1 -1
- data/app/controllers/foreman_acd/concerns/app_instance_parameters.rb +1 -1
- data/app/controllers/foreman_acd/remote_execution_controller.rb +46 -0
- data/app/controllers/ui_acd_controller.rb +20 -4
- data/app/lib/actions/foreman_acd/deploy_all_hosts.rb +42 -0
- data/app/lib/actions/foreman_acd/run_configurator.rb +41 -0
- data/app/models/concerns/foreman_acd/host_managed_extensions.rb +51 -0
- data/app/models/foreman_acd/acd_provider.rb +30 -0
- data/app/models/foreman_acd/ansible_playbook.rb +67 -0
- data/app/models/foreman_acd/app_definition.rb +25 -1
- data/app/models/foreman_acd/app_instance.rb +42 -0
- data/app/models/foreman_acd/foreman_host.rb +23 -0
- data/app/models/foreman_acd/taxonomy_extensions.rb +17 -0
- data/app/services/foreman_acd/app_configurator.rb +54 -0
- data/app/services/foreman_acd/app_deployer.rb +151 -0
- data/app/services/foreman_acd/inventory_creator.rb +54 -0
- data/app/views/foreman_acd/ansible_playbooks/_form.html.erb +30 -0
- data/app/views/foreman_acd/ansible_playbooks/edit.html.erb +11 -0
- data/app/views/foreman_acd/ansible_playbooks/index.html.erb +30 -0
- data/app/views/foreman_acd/ansible_playbooks/new.html.erb +3 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/ansible_playbooks/show.json.rabl +9 -0
- data/app/views/foreman_acd/api/v2/app_definitions/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_definitions/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_definitions/show.json.rabl +9 -0
- data/app/views/foreman_acd/api/v2/app_instances/base.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_instances/index.json.rabl +5 -0
- data/app/views/foreman_acd/api/v2/app_instances/show.json.rabl +5 -0
- data/app/views/foreman_acd/app_definitions/_form.html.erb +34 -20
- data/app/views/foreman_acd/app_definitions/edit.html.erb +10 -0
- data/app/views/foreman_acd/app_definitions/import.html.erb +18 -0
- data/app/views/foreman_acd/app_definitions/index.html.erb +10 -6
- data/app/views/foreman_acd/app_instances/_form.html.erb +12 -10
- data/app/views/foreman_acd/app_instances/edit.html.erb +10 -0
- data/app/views/foreman_acd/app_instances/index.html.erb +87 -9
- data/app/views/foreman_acd/app_instances/report.html.erb +22 -0
- data/app/views/templates/job/run_acd_ansible_playbook.erb +62 -0
- data/app/views/ui_acd/ansible_data.json.rabl +6 -0
- data/app/views/ui_acd/app.json.rabl +6 -2
- data/app/views/ui_acd/app_definition.json.rabl +1 -1
- data/app/views/ui_acd/{fdata.json.rabl → foreman_data.json.rabl} +1 -1
- data/config/routes.rb +35 -1
- data/db/migrate/20190610202252_create_app_definitions.rb +1 -3
- data/db/migrate/20190625140305_create_app_instances.rb +1 -1
- data/db/migrate/20200916091018_create_ansible_playbooks.rb +20 -0
- data/db/migrate/20200917120220_add_ansible_playbook_id.rb +14 -0
- data/db/migrate/20201016002819_add_ansible_vars_all_to_app_definitions.rb +8 -0
- data/db/migrate/20201016104338_add_ansible_vars_all_to_app_instances.rb +8 -0
- data/db/migrate/20210112111548_add_organization_to_app_instance.rb +22 -0
- data/db/migrate/20210112113853_add_location_to_app_instance.rb +8 -0
- data/db/migrate/20210202141658_create_foreman_hosts.rb +24 -0
- data/db/migrate/20210204111306_remove_hosts_from_app_instances.rb +8 -0
- data/db/migrate/20210209091014_rename_acd_tables.rb +16 -0
- data/db/migrate/20210216083522_add_last_progress_report.rb +8 -0
- data/db/migrate/20210216091529_add_last_deploy_task.rb +8 -0
- data/db/seeds.d/62_acd_proxy_feature.rb +4 -0
- data/db/seeds.d/75-job_templates.rb +13 -0
- data/lib/foreman_acd/engine.rb +21 -3
- data/lib/foreman_acd/plugin.rb +112 -20
- data/lib/foreman_acd/version.rb +1 -1
- data/locale/en/foreman_acd.edit.po +326 -0
- data/locale/en/foreman_acd.po +232 -2
- data/locale/en/foreman_acd.po.time_stamp +0 -0
- data/locale/foreman_acd.pot +343 -8
- data/package.json +1 -1
- data/test/controllers/ansible_playbooks_controller_test.rb +27 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.js +391 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinition.scss +1 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionActions.js +303 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionConstants.js +15 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionHelper.js +26 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionReducer.js +269 -0
- data/webpack/components/ApplicationDefinition/ApplicationDefinitionSelectors.js +9 -0
- data/webpack/components/ApplicationDefinition/components/AnsiblePlaybookSelector.js +49 -0
- data/webpack/components/ApplicationDefinition/index.js +35 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.js +451 -0
- data/webpack/components/ApplicationInstance/ApplicationInstance.scss +11 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceActions.js +247 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceConstants.js +15 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceReducer.js +309 -0
- data/webpack/components/ApplicationInstance/ApplicationInstanceSelectors.js +10 -0
- data/webpack/components/ApplicationInstance/components/AppDefinitionSelector.js +49 -0
- data/webpack/components/ApplicationInstance/components/Service.js +30 -0
- data/webpack/components/ApplicationInstance/components/ServiceCounter.js +37 -0
- data/webpack/components/ApplicationInstance/index.js +37 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.js +148 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReport.scss +44 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportActions.js +42 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportConstants.js +2 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportReducer.js +38 -0
- data/webpack/components/ApplicationInstanceReport/ApplicationInstanceReportSelectors.js +4 -0
- data/webpack/components/ApplicationInstanceReport/components/ReportViewer.js +26 -0
- data/webpack/components/ApplicationInstanceReport/index.js +25 -0
- data/webpack/components/ParameterSelection/ParameterSelection.js +131 -192
- data/webpack/components/ParameterSelection/ParameterSelection.scss +9 -0
- data/webpack/components/ParameterSelection/ParameterSelectionActions.js +87 -110
- data/webpack/components/ParameterSelection/ParameterSelectionConstants.js +15 -19
- data/webpack/components/ParameterSelection/ParameterSelectionHelper.js +3 -35
- data/webpack/components/ParameterSelection/ParameterSelectionReducer.js +116 -84
- data/webpack/components/ParameterSelection/ParameterSelectionSelectors.js +3 -7
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelection.fixtures.js +12 -21
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionData_1.fixtures.js +1 -1
- data/webpack/components/ParameterSelection/__fixtures__/parameterSelectionReducer.fixtures.js +3 -45
- data/webpack/components/ParameterSelection/__tests__/ParameterSelection.test.js +20 -0
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionReducer.test.js +22 -46
- data/webpack/components/ParameterSelection/__tests__/ParameterSelectionSelectors.test.js +6 -6
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelection.test.js.snap +40 -265
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionReducer.test.js.snap +11 -96
- data/webpack/components/ParameterSelection/__tests__/__snapshots__/ParameterSelectionSelectors.test.js.snap +3 -9
- data/webpack/components/ParameterSelection/index.js +6 -8
- data/webpack/components/common/AddTableEntry.js +30 -0
- data/webpack/components/common/DeleteTableEntry.js +39 -0
- data/webpack/components/common/EasyHeaderFormatter.js +18 -0
- data/webpack/components/common/EditTableEntry.js +50 -0
- data/webpack/components/common/ExtSelect.js +43 -0
- data/webpack/components/common/LockTableEntry.js +60 -0
- data/webpack/components/common/RailsData.js +27 -0
- data/webpack/components/common/__tests__/AddTableEntry.test.js +26 -0
- data/webpack/components/common/__tests__/DeleteTableEntry.test.js +29 -0
- data/webpack/components/common/__tests__/ExtSelect.test.js +38 -0
- data/webpack/components/common/__tests__/RailsData.test.js +16 -0
- data/webpack/components/common/__tests__/__snapshots__/AddParameter.test.js.snap +35 -0
- data/webpack/components/common/__tests__/__snapshots__/AddTableEntry.test.js.snap +35 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteParameter.test.js.snap +41 -0
- data/webpack/components/common/__tests__/__snapshots__/DeleteTableEntry.test.js.snap +41 -0
- data/webpack/components/common/__tests__/__snapshots__/ExtSelect.test.js.snap +18 -0
- data/webpack/components/common/__tests__/__snapshots__/RailsData.test.js.snap +10 -0
- data/webpack/helper.js +20 -0
- data/webpack/index.js +6 -0
- data/webpack/reducer.js +43 -3
- metadata +114 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 809d34cc7063d66a26a1c0c913cd95287a6329cce55a75c1684046bb47b1afe1
|
|
4
|
+
data.tar.gz: d32aa387545b3fac503996354baae6704c30118a923d95706668895cad6440f5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 996b0c911e71e045b232b3d6b27776eaa9c7e6c52f23f78d29c911f899d4a60024990fa8866e2f401e2d91f1c2a0c06a7264f16ffc2e4bd0b97c0e794a0a7c63
|
|
7
|
+
data.tar.gz: 445dc99ec810e7fbbdf33d2c1e69b3a60942c58938212105033e472981bee85e626ce51d7e2f36359bbfb9148dca240fff134d183481d1d8312a3e9f933f4815
|
data/README.md
CHANGED
|
@@ -2,88 +2,139 @@
|
|
|
2
2
|
|
|
3
3
|
# Foreman Application Centric Deployment
|
|
4
4
|
|
|
5
|
-
A plugin
|
|
5
|
+
A Foreman plugin providing application centric deployment and a self-service portal.
|
|
6
6
|
|
|
7
|
-
#
|
|
7
|
+
# Introduction
|
|
8
8
|
|
|
9
|
-
The target of this plugin is
|
|
10
|
-
and an Ansible Playbook / saltstack state to configure the application.
|
|
9
|
+
The target of this plugin is to deploy whole applications which include multiple hosts and configure them using an Ansible playbook.
|
|
11
10
|
|
|
12
11
|
This plugin follows the idea of different user types working together.
|
|
13
|
-
The
|
|
14
|
-
|
|
15
|
-
The user can create and deploy new application instances with an easy to use self service portal.
|
|
12
|
+
The _administrative user_ creates Application Definitions including multiple servers and configuration management items (Ansible Playbooks).
|
|
13
|
+
The _user_ can create and deploy new Application Instances with an easy to use self-service portal.
|
|
16
14
|
|
|
17
|
-
*Example Application Definition
|
|
18
|
-
To run a complex web application, a
|
|
19
|
-
The
|
|
20
|
-
The web servers are using a database which
|
|
21
|
-
|
|
15
|
+
*Example Application Definition*
|
|
16
|
+
To run a complex web application, a load balancer is required.
|
|
17
|
+
The load balancer routes the requests to three different web servers.
|
|
18
|
+
The web servers are using a database which runs in high availability mode on two hosts.
|
|
19
|
+
Therefore, six hosts in total are required.
|
|
22
20
|
|
|
23
|
-
This plugin aims to setup all
|
|
21
|
+
This plugin aims to setup all six hosts and to deploy the application.
|
|
24
22
|
|
|
25
|
-
#
|
|
26
|
-
In the current state the plugin can be used to provide an easy to use self service user portal
|
|
27
|
-
to deploy new servers.
|
|
23
|
+
# Architecture
|
|
28
24
|
|
|
29
|
-
|
|
30
|
-
- Self service portal for single host deployments (current version)
|
|
31
|
-
- Add application deployment with single host requirements
|
|
32
|
-
- Add application deployment with multi host requirements
|
|
25
|
+
## Ansible Playbooks
|
|
33
26
|
|
|
34
|
-
|
|
27
|
+
* Specify the path on your Foreman server to the Ansible playbook and playfile
|
|
28
|
+
* Read groups configured in the Ansible playbook
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
|
|
30
|
+
## Application Definitions
|
|
31
|
+
|
|
32
|
+
* Use the configured Ansible playbook in an Application Definition
|
|
33
|
+
* Overwrite group variables of the Ansible playbook for the Application Definition
|
|
34
|
+
* Set Foreman parameters in the Application Definition
|
|
35
|
+
* Setup various services like web servers, database servers, etc.
|
|
36
|
+
|
|
37
|
+
## Application Instances
|
|
38
|
+
|
|
39
|
+
* Use an Application Definition for your Application Instance
|
|
40
|
+
* Configure specific hosts which use the Application Definition's services
|
|
41
|
+
* Deploy these hosts
|
|
42
|
+
* Configure the hosts using the configured Ansible playbook
|
|
43
|
+
|
|
44
|
+
# How It Works
|
|
45
|
+
|
|
46
|
+
* Configure an Ansible playbook, an Application Definition, and create an Application Instance.
|
|
47
|
+
* All hosts are created when deploying the Application Instance.
|
|
48
|
+
* After provisioning, the hosts are configured with the linked Ansible playbook.
|
|
49
|
+
* This uses the [Smart Proxy ACD](https://github.com/ATIX-AG/smart_proxy_acd) component.
|
|
50
|
+
* The job to configure the hosts will be send to the Smart Proxy ACD component which will
|
|
51
|
+
* download the Ansible playbook from your Foreman server (provided by an foreman_acd API);
|
|
52
|
+
* extract the Ansible playbook on the Smart Proxy;
|
|
53
|
+
* and run the Ansible playbook on the Smart Proxy.
|
|
54
|
+
* You can see the output of the Ansible playbook run on the *Monitor > Job* page.
|
|
55
|
+
|
|
56
|
+
:warning: This plugin is still in development.
|
|
38
57
|
|
|
39
58
|
## Installation
|
|
40
59
|
|
|
41
|
-
See [
|
|
42
|
-
|
|
60
|
+
See the [installation](https://theforeman.org/plugins/#2.Installation) chapter of the Foreman plugins documentation on how to install Foreman plugins.
|
|
61
|
+
|
|
62
|
+
### TL;DR:
|
|
63
|
+
|
|
64
|
+
yum install tfm-rubygem-foreman_acd
|
|
65
|
+
foreman-maintain service restart
|
|
66
|
+
|
|
67
|
+
In some cases, you need to manually run
|
|
68
|
+
|
|
69
|
+
foreman-rake db:migrate
|
|
70
|
+
foreman-rake db:seed
|
|
71
|
+
|
|
72
|
+
### Smart Proxy Installation
|
|
73
|
+
|
|
74
|
+
You will need to install [Smart Proxy ACD](https://github.com/ATIX-AG/smart_proxy_acd), too.
|
|
43
75
|
|
|
44
|
-
|
|
76
|
+
yum install tfm-rubygem-smart_proxy_acd tfm-rubygem-smart_proxy_acd_core
|
|
77
|
+
foreman-maintain service restart
|
|
78
|
+
|
|
79
|
+
You need to refresh the smart proxy features in *Infrastructure > Smart Proxies > Your Smart-Proxy > Actions > Refresh* after the installation of the Smart Proxy ACD components.
|
|
80
|
+
|
|
81
|
+
### Tips
|
|
82
|
+
|
|
83
|
+
* Make sure you have the [Katello](https://theforeman.org/plugins/katello/) plugin installed.
|
|
84
|
+
* Make sure the Job Template `Run ACD Ansible Playbook - ACD Default` is part of your organization/location context.
|
|
45
85
|
|
|
46
86
|
## Usage
|
|
47
87
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
|
|
88
|
+
### Ansible Playbook
|
|
89
|
+
|
|
90
|
+
* Copy (or checkout a git repository) an Ansible playbook.
|
|
91
|
+
Store it in `/etc/foreman/plugins/foreman_acd/ansible-playbooks/` so that SELinux is able to read it.
|
|
92
|
+
* Add a new Ansible Playbook via *Applications > Ansible Playbooks*.
|
|
93
|
+
* Specify the path to the Ansible playbook and name of the playbook file. (e.g. `site.yml`).
|
|
94
|
+
* Save it and press *Import group variables* for this newly created Ansible playbook.
|
|
95
|
+
|
|
96
|
+
### Application Definition (for Admins)
|
|
97
|
+
|
|
98
|
+
* Create an Application Definition via *Applications > Application Definitions*.
|
|
99
|
+
* Select the Ansible Playbook you want to use.
|
|
100
|
+
* Add new services and specify the host group you want to use.
|
|
101
|
+
* Specify any values a user will be allowed to overwrite.
|
|
102
|
+
You may also set a default value.
|
|
103
|
+
|
|
104
|
+
### Application Instance (for Users)
|
|
105
|
+
|
|
106
|
+
* Create an Application Instance via *Applications > Application Instances*.
|
|
107
|
+
* Select the Application Definition you want to use.
|
|
108
|
+
* Overwrite desired values.
|
|
109
|
+
All Foreman parameters require a value.
|
|
110
|
+
* Save the Application Instance.
|
|
111
|
+
|
|
112
|
+
### Deploy and Configure the Application Instance (for Users)
|
|
113
|
+
|
|
114
|
+
* Select *Deploy* in the action drop down menu via *Applications > Application Instance* to deploy a host.
|
|
115
|
+
* Verify if the hosts are deployed via the *Report* button from the action drop down menu.
|
|
116
|
+
* Run the Ansible playbook via *Run Ansible playbook* from the action drop down menu after all hosts are deployed.
|
|
62
117
|
|
|
63
118
|
## TODO
|
|
64
119
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
120
|
+
* Add `git` support for the Ansible playbooks.
|
|
121
|
+
* Provide application templates which contains application definition and the required Ansible-playbook.
|
|
122
|
+
* Add Saltstack support to configure the application.
|
|
123
|
+
* Extend the Foreman parameter and value validation.
|
|
68
124
|
|
|
69
125
|
## Contributing
|
|
70
126
|
|
|
71
|
-
Fork and send a Pull Request.
|
|
127
|
+
Fork and send a Pull Request.
|
|
128
|
+
Thanks!
|
|
72
129
|
|
|
73
130
|
## Copyright
|
|
74
131
|
|
|
75
|
-
Copyright (c)
|
|
76
|
-
|
|
77
|
-
This program is free software: you can redistribute it and/or modify
|
|
78
|
-
it under the terms of the GNU General Public License as published by
|
|
79
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
80
|
-
(at your option) any later version.
|
|
132
|
+
Copyright (c) 2021 ATIX AG
|
|
81
133
|
|
|
82
|
-
This program is
|
|
83
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
84
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
85
|
-
GNU General Public License for more details.
|
|
134
|
+
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
|
86
135
|
|
|
87
|
-
|
|
88
|
-
|
|
136
|
+
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
137
|
+
See the GNU General Public License for more details.
|
|
89
138
|
|
|
139
|
+
You should have received a copy of the GNU General Public License along with this program.
|
|
140
|
+
If not, see <http://www.gnu.org/licenses/>.
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ForemanAcd
|
|
4
|
+
# Ansible Playbook Controller
|
|
5
|
+
class AnsiblePlaybooksController < ::ForemanAcd::ApplicationController
|
|
6
|
+
include Foreman::Controller::AutoCompleteSearch
|
|
7
|
+
include ::ForemanAcd::Concerns::AnsiblePlaybookParameters
|
|
8
|
+
|
|
9
|
+
before_action :find_resource, :only => [:edit, :update, :destroy, :import_vars]
|
|
10
|
+
|
|
11
|
+
def index
|
|
12
|
+
@ansible_playbooks = resource_base.search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def new
|
|
16
|
+
@ansible_playbook = AnsiblePlaybook.new
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def create
|
|
20
|
+
@ansible_playbook = AnsiblePlaybook.new(ansible_playbook_params)
|
|
21
|
+
if @ansible_playbook.save
|
|
22
|
+
process_success :success_msg => _("Successfully created %s. You need to press the \"Import groups\" button
|
|
23
|
+
before this ansible playbook can be used in App Definitions!") % @ansible_playbook
|
|
24
|
+
else
|
|
25
|
+
process_error
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def edit; end
|
|
30
|
+
|
|
31
|
+
def update
|
|
32
|
+
if @ansible_playbook.update(ansible_playbook_params)
|
|
33
|
+
process_success
|
|
34
|
+
else
|
|
35
|
+
process_error
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def destroy
|
|
40
|
+
if @ansible_playbook.destroy
|
|
41
|
+
process_success
|
|
42
|
+
else
|
|
43
|
+
process_error
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def action_permission
|
|
48
|
+
case params[:action]
|
|
49
|
+
when 'import_vars'
|
|
50
|
+
:import_vars
|
|
51
|
+
when 'grab'
|
|
52
|
+
:grab
|
|
53
|
+
else
|
|
54
|
+
super
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# We need to move these to a smart_proxy_acd
|
|
59
|
+
def extract_variables(playbook_path)
|
|
60
|
+
errors = []
|
|
61
|
+
vars = {}
|
|
62
|
+
|
|
63
|
+
unless File.directory?(playbook_path) || File.directory?("#{playbook_path}/group_vars")
|
|
64
|
+
errors << "Playbook path '#{playbook_path}' or '#{playbook_path}/group_vars' doesn't exist"
|
|
65
|
+
return vars, errors
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
everything_empty = true
|
|
69
|
+
|
|
70
|
+
vars_files = Dir.glob("#{playbook_path}/group_vars/**/*")
|
|
71
|
+
vars_files.each do |vars_file|
|
|
72
|
+
loaded_yaml = {}
|
|
73
|
+
next if File.directory?(vars_file)
|
|
74
|
+
|
|
75
|
+
begin
|
|
76
|
+
loaded_yaml = YAML.load_file(vars_file)
|
|
77
|
+
rescue Psych::SyntaxError
|
|
78
|
+
err = "#{vars_file} is not YAML file"
|
|
79
|
+
logger.error(err)
|
|
80
|
+
errors << err
|
|
81
|
+
end
|
|
82
|
+
unless loaded_yaml.is_a? Hash
|
|
83
|
+
err = "Could not parse YAML file #{vars_file}"
|
|
84
|
+
logger.error(err)
|
|
85
|
+
errors << err
|
|
86
|
+
end
|
|
87
|
+
everything_empty = false unless loaded_yaml.empty?
|
|
88
|
+
|
|
89
|
+
# We need to support: group_vars/group_file and group_vars/group_dir/yaml_files
|
|
90
|
+
dir_and_file = File.split(vars_file)
|
|
91
|
+
|
|
92
|
+
group_name = if File.basename(dir_and_file[0]) == 'group_vars' # in case of group_vars/group_file
|
|
93
|
+
File.basename(dir_and_file[1], '.*')
|
|
94
|
+
else # in case of group_vars/group_dir/yaml_files
|
|
95
|
+
File.basename(dir_and_file[0])
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
logger.debug("Add ansible vars from file #{vars_file} to group #{group_name}")
|
|
99
|
+
|
|
100
|
+
if vars.key?(group_name)
|
|
101
|
+
vars[group_name].merge!(loaded_yaml)
|
|
102
|
+
else
|
|
103
|
+
vars[group_name] = loaded_yaml
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
errors << "No ansible group variable in #{playbook_path} defined." if everything_empty
|
|
108
|
+
|
|
109
|
+
[vars, errors]
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def import_vars
|
|
113
|
+
logger.debug("Load ansible group vars for #{@ansible_playbook} from #{@ansible_playbook.path}")
|
|
114
|
+
vars, errors = extract_variables(@ansible_playbook.path)
|
|
115
|
+
@ansible_playbook.vars = vars.to_json
|
|
116
|
+
@ansible_playbook.save
|
|
117
|
+
if errors.empty?
|
|
118
|
+
process_success :success_msg => _('Successfully loaded ansible group variables from %s') % @ansible_playbook.name, :redirect => ansible_playbooks_path
|
|
119
|
+
else
|
|
120
|
+
process_error :error_msg => _(errors.join(' ')), :redirect => ansible_playbooks_path
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ForemanAcd
|
|
4
|
+
module Api
|
|
5
|
+
module V2
|
|
6
|
+
# API controller for Ansible Playbooks
|
|
7
|
+
class AnsiblePlaybooksController < ::ForemanAcd::Api::V2::BaseController
|
|
8
|
+
include ::Foreman::Controller::SmartProxyAuth
|
|
9
|
+
include ::ForemanAcd::Concerns::AnsiblePlaybookParameters
|
|
10
|
+
|
|
11
|
+
before_action :find_resource, :except => [:index, :create, :grab]
|
|
12
|
+
|
|
13
|
+
add_smart_proxy_filters :grab, :features => 'ACD'
|
|
14
|
+
|
|
15
|
+
api :GET, '/ansible_playbooks/:id', N_('Show ansible playbook')
|
|
16
|
+
param :id, :identifier, :required => true
|
|
17
|
+
def show; end
|
|
18
|
+
|
|
19
|
+
api :GET, '/ansible_playbooks', N_('List ansible playbooks')
|
|
20
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
|
21
|
+
add_scoped_search_description_for(AnsiblePlaybook)
|
|
22
|
+
def index
|
|
23
|
+
@ansible_playbooks = resource_scope_for_index
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def_param_group :ansible_playbook do
|
|
27
|
+
param :ansible_playbook, Hash, :required => true, :action_aware => true do
|
|
28
|
+
param :name, String, :required => true
|
|
29
|
+
param_group :taxonomies, ::Api::V2::BaseController
|
|
30
|
+
param :description, String, :required => true
|
|
31
|
+
param :services, String, :required => true
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
api :POST, '/ansible_playbooks', N_('Create a ansible playbook')
|
|
36
|
+
param_group :ansible_playbook, :as => :create
|
|
37
|
+
def create
|
|
38
|
+
@ansible_playbook = AnsiblePlaybook.new(ansible_playbook_params)
|
|
39
|
+
process_response @ansible_playbook.save
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
api :DELETE, '/ansible_playbooks/:id', N_('Deletes ansible playbook')
|
|
43
|
+
param :id, :identifier, :required => true
|
|
44
|
+
def destroy
|
|
45
|
+
process_response @ansible_playbook.destroy
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
api :GET, '/ansible_playbooks/:id/grab', N_('Grab ansible playbook')
|
|
49
|
+
param :id, :identifier, :required => true
|
|
50
|
+
def grab
|
|
51
|
+
ap = resource_class.find(params['id'])
|
|
52
|
+
command = "tar cz -C #{ap.path} --exclude \".git\" . 2>/dev/null | base64"
|
|
53
|
+
result = `#{command}`
|
|
54
|
+
send_data result, :type => 'text/plain', :disposition => 'inline'
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def action_permission
|
|
58
|
+
case params[:action]
|
|
59
|
+
when 'grab'
|
|
60
|
+
'grab'
|
|
61
|
+
else
|
|
62
|
+
super
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def resource_class
|
|
67
|
+
ForemanAcd::AnsiblePlaybook
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
@@ -23,9 +23,9 @@ module ForemanAcd
|
|
|
23
23
|
def_param_group :app_definition do
|
|
24
24
|
param :app_definition, Hash, :required => true, :action_aware => true do
|
|
25
25
|
param :name, String, :required => true
|
|
26
|
+
param_group :taxonomies, ::Api::V2::BaseController
|
|
26
27
|
param :description, String, :required => true
|
|
27
|
-
param :
|
|
28
|
-
param :parameters, String, :required => true
|
|
28
|
+
param :services, String, :required => true
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module ForemanAcd
|
|
4
|
+
module Api
|
|
5
|
+
module V2
|
|
6
|
+
# API controller for App Instances
|
|
7
|
+
class AppInstancesController < ::ForemanAcd::Api::V2::BaseController
|
|
8
|
+
include ::ForemanAcd::Concerns::AppInstanceParameters
|
|
9
|
+
|
|
10
|
+
before_action :find_resource, :except => [:index, :create]
|
|
11
|
+
|
|
12
|
+
api :GET, '/app_instances/:id', N_('Show application instance')
|
|
13
|
+
param :id, :identifier, :required => true
|
|
14
|
+
param :organization_id, :identifier, :required => true
|
|
15
|
+
param :location_id, :identifier, :required => true
|
|
16
|
+
def show; end
|
|
17
|
+
|
|
18
|
+
api :GET, '/app_instances', N_('List application instances')
|
|
19
|
+
param :organization_id, :identifier, :required => true
|
|
20
|
+
param :location_id, :identifier, :required => true
|
|
21
|
+
param_group :search_and_pagination, ::Api::V2::BaseController
|
|
22
|
+
add_scoped_search_description_for(AppInstance)
|
|
23
|
+
def index
|
|
24
|
+
scope = resource_scope_for_index.where(:organization => params[:organization_id]) if params[:organization_id].present?
|
|
25
|
+
scope = scope.where(:location => params[:location_id]) if params[:location_id].present?
|
|
26
|
+
@app_instances = scope
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def_param_group :app_instance do
|
|
30
|
+
param :app_instance, Hash, :required => true, :action_aware => true do
|
|
31
|
+
param :name, String, :required => true
|
|
32
|
+
param :organization_id, :identifier, :required => true
|
|
33
|
+
param :location_id, :identifier, :required => true
|
|
34
|
+
param :description, String, :required => true
|
|
35
|
+
param :services, String, :required => true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
api :POST, '/app_instances', N_('Create a application instance')
|
|
40
|
+
param_group :app_instance, :as => :create
|
|
41
|
+
def create
|
|
42
|
+
@app_instance = AppInstance.new(app_instance_params)
|
|
43
|
+
process_response @app_instance.save
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
api :DELETE, '/app_instances/:id', N_('Deletes application instance')
|
|
47
|
+
param :id, :identifier, :required => true
|
|
48
|
+
def destroy
|
|
49
|
+
process_response @app_instance.destroy
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def controller_permission
|
|
53
|
+
'app_instances'
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def resource_class
|
|
57
|
+
ForemanAcd::AppInstance
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|