Skip to content

Commit

Permalink
fixes #25009 - fix sync script and sync templates (theforeman#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
stbenjam authored and ares committed Oct 26, 2018
1 parent e4556a3 commit a7a4335
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<%#
kind: job_template
name: Module Action - Ansible Default
model: JobTemplate
job_category: Ansible Modules
description_format: "Module %{action} %{module_spec}"
provider_type: Ansible
template_inputs:
- name: pre_script
description: A script to run prior to the module action
input_type: user
required: false
advanced: true
- name: action
description: 'The module action enable, install etc'
input_type: user
required: true
options: "\nlist\ninfo\nenable\ndisable\ninstall\nupdate\nremove\nprovides\nlock\nunlock\nprofile\nstreams"
- name: module_spec
description: The module specification. module:stream/profile
input_type: user
required: false
- name: options
description: Other optional flags for the action
input_type: user
required: false
- name: post_script
description: A script to run after the module action
input_type: user
required: false
advanced: true
%>

<% command = "dnf -y module #{input(:action)} #{input(:module_spec)} #{input(:options)}" %>

---
- hosts: all
<%- if input('pre_script').present? -%>
pre_tasks:
- shell: "<%= input('pre_script') %>"
<%- end -%>
tasks:
- shell: |
<%= indent(8) { command } %>
register: out
args:
warn: false
- debug: var=out
<%- if input('post_script').present? -%>
post_tasks:
- shell: "<%= input('post_script') %>"
<%- end -%>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ model: JobTemplate
- hosts: all
tasks:
- command: |
echo <%= input('action') %> host && sleep 3
<%= case input('action')
when 'restart'
'shutdown -r +1'
Expand Down
41 changes: 28 additions & 13 deletions script/sync_templates.sh
Original file line number Diff line number Diff line change
@@ -1,26 +1,41 @@
#!/bin/bash
#
# Copies unattended templates from community-templates repository to
# app/views/unattended/ where they can be seeded on new installations.
# Copies job templates from community-templates repository to
# app/views/foreman_ansbile/job_templates so they can be seeded on new
# installations.
#
# Not intended for use on existing installations, only for development.
# Production installations should use the foreman_templates plugin to
# update the contents of the database.
# Part of the release process.

REPO=$(mktemp -d)
trap "rm -rf $REPO" EXIT
shopt -s extglob

git clone -q -b develop \
https://github.com/theforeman/community-templates $REPO/ct
git clone -q -b develop https://github.com/theforeman/community-templates $REPO/ct

# move into destination dir if run from Foreman root
[ -d app/views/foreman_ansible/ ] && cd app/views/foreman_ansible/
pushd $PWD
cd $REPO/ct/job_templates

rsync -am \
--include='*ansible*' \
--exclude='*' \
$REPO/ct/job_templates/* ./job_templates
# Delete all non-ansible templates and remove suffix
rm !(*_-_ansible_default.erb)

popd

# Move into destination dir if run from plugin root
[ -d app/views/templates/ssh ] && cd app/views/templates/ssh
[ -d app/views/foreman_ansible/job_templates/ ] && cd app/views/foreman_ansible/job_templates/

rsync -r \
--exclude README.md \
--exclude '.*' \
--exclude test \
--exclude Rakefile \
$REPO/ct/job_templates/*.erb ./

cd -

git status -- app/views/foreman_ansible/job_templates

if [ $(git status --porcelain -u -- app/views/foreman_ansible/job_templates | grep -c '^\?') -gt 0 ]; then
echo
echo "Warning: new files copied, be sure to commit them and ensure they are seeded."
fi

0 comments on commit a7a4335

Please sign in to comment.