Divide add config and rproxy installation
This commit is contained in:
50
Jenkinsfile
vendored
50
Jenkinsfile
vendored
@@ -11,13 +11,8 @@ pipeline {
|
|||||||
timestamps()
|
timestamps()
|
||||||
}
|
}
|
||||||
parameters {
|
parameters {
|
||||||
string(name: "target_host", defaultValue: "", trim: true, description: "Target host")
|
string(name: "target_host", defaultValue: "", trim: true, description: "Target host for rproxy installation")
|
||||||
booleanParam(name: "rproxy_install", defaultValue: true, description: "Install Rproxy")
|
string(name: "images_repo_url", defaultValue: "", trim: true, description: "Repository host with podman images (ex. rproxy.olsson.ul:5000)")
|
||||||
string(name: "images_repo_url", defaultValue: "", trim: true, description: "Repository host with podman images (ex. rproxy.olsson.ul:5000)\n(for 'rproxy_install' job only)")
|
|
||||||
booleanParam(name: "config_add", defaultValue: true, description: "Add config")
|
|
||||||
string(name: "rproxy_service_name", defaultValue: "", trim: true, description: "Service name (for 'Add config' job only)")
|
|
||||||
string(name: "rproxy_service_port", defaultValue: "", trim: true, description: "Service port (for 'Add config' job only)")
|
|
||||||
string(name: "rproxy_service_address", defaultValue: "", trim: true, description: "Service address (for 'Add config' job only)")
|
|
||||||
booleanParam(name: 'update_job', defaultValue: false, description: 'Update job, free run, no changes')
|
booleanParam(name: 'update_job', defaultValue: false, description: 'Update job, free run, no changes')
|
||||||
}
|
}
|
||||||
stages {
|
stages {
|
||||||
@@ -45,11 +40,6 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Install Rproxy') {
|
stage('Install Rproxy') {
|
||||||
when {
|
|
||||||
expression {
|
|
||||||
return params.rproxy_install
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
steps {
|
||||||
script {
|
script {
|
||||||
withCredentials([
|
withCredentials([
|
||||||
@@ -61,14 +51,10 @@ pipeline {
|
|||||||
ansiblePlaybook(
|
ansiblePlaybook(
|
||||||
playbook: 'rproxy.yml',
|
playbook: 'rproxy.yml',
|
||||||
inventory: 'hosts.ini',
|
inventory: 'hosts.ini',
|
||||||
tags: 'install',
|
|
||||||
colorized: true,
|
colorized: true,
|
||||||
extras: '''--private-key ${SSH_KEY}
|
extras: '''--private-key ${SSH_KEY}
|
||||||
-e "ansible_user=${username}
|
-e "ansible_user=${username}
|
||||||
ansible_password=${password}
|
ansible_password=${password}
|
||||||
rproxy_service_name=${rproxy_service_name}
|
|
||||||
rproxy_service_port=${rproxy_service_port}
|
|
||||||
rproxy_service_address=${rproxy_service_address}
|
|
||||||
image_repo=${images_repo_url}"'''
|
image_repo=${images_repo_url}"'''
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -77,38 +63,6 @@ pipeline {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stage('Add config') {
|
|
||||||
when {
|
|
||||||
expression {
|
|
||||||
return params.config_add
|
|
||||||
}
|
|
||||||
}
|
|
||||||
steps {
|
|
||||||
script {
|
|
||||||
withCredentials([
|
|
||||||
sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'),
|
|
||||||
usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password')
|
|
||||||
]) {
|
|
||||||
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) {
|
|
||||||
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: "xterm"]) {
|
|
||||||
ansiblePlaybook(
|
|
||||||
playbook: 'rproxy.yml',
|
|
||||||
inventory: 'hosts.ini',
|
|
||||||
tags: 'add_config',
|
|
||||||
colorized: true,
|
|
||||||
extras: '''--private-key ${SSH_KEY}
|
|
||||||
-e "ansible_user=${username}
|
|
||||||
ansible_password=${password}
|
|
||||||
rproxy_service_name=${rproxy_service_name}
|
|
||||||
rproxy_service_port=${rproxy_service_port}
|
|
||||||
rproxy_service_address=${rproxy_service_address}"'''
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
post {
|
post {
|
||||||
always {
|
always {
|
||||||
|
|||||||
19
addconfig.yml
Normal file
19
addconfig.yml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
become: yes
|
||||||
|
|
||||||
|
vars_prompt:
|
||||||
|
- name: rproxy_service_name
|
||||||
|
prompt: Enter service for rproxy
|
||||||
|
private: false
|
||||||
|
|
||||||
|
- name: rproxy_service_port
|
||||||
|
prompt: Enter service for rproxy
|
||||||
|
private: false
|
||||||
|
|
||||||
|
- name: rproxy_service_address
|
||||||
|
prompt: Enter service for rproxy
|
||||||
|
private: false
|
||||||
|
|
||||||
|
roles:
|
||||||
|
- addconfig
|
||||||
@@ -3,3 +3,6 @@ hostfile = hosts.ini
|
|||||||
host_key_checking = false
|
host_key_checking = false
|
||||||
interpreter_python = /usr/bin/python3
|
interpreter_python = /usr/bin/python3
|
||||||
forks = 30
|
forks = 30
|
||||||
|
|
||||||
|
[ssh_connection]
|
||||||
|
pipelining = true
|
||||||
80
management/AddService.groovy
Normal file
80
management/AddService.groovy
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
pipeline {
|
||||||
|
agent any
|
||||||
|
options {
|
||||||
|
buildDiscarder logRotator (
|
||||||
|
numToKeepStr: '5',
|
||||||
|
daysToKeepStr: '7',
|
||||||
|
artifactNumToKeepStr: '10',
|
||||||
|
artifactDaysToKeepStr: '7'
|
||||||
|
)
|
||||||
|
ansiColor('xterm')
|
||||||
|
timestamps()
|
||||||
|
}
|
||||||
|
parameters {
|
||||||
|
string(name: "target_host", defaultValue: "", trim: true, description: "Target host with rproxy installed")
|
||||||
|
string(name: "rproxy_service_name", defaultValue: "", trim: true, description: "Service name (ex. jenkins)")
|
||||||
|
string(name: "rproxy_service_port", defaultValue: "", trim: true, description: "Service port (ex. 8080)")
|
||||||
|
string(name: "rproxy_service_address", defaultValue: "", trim: true, description: "Service address (ex. jenkins-master.olsson.ul)")
|
||||||
|
booleanParam(name: 'update_job', defaultValue: false, description: 'Update job, free run, no changes')
|
||||||
|
}
|
||||||
|
stages {
|
||||||
|
stage('Update Job') {
|
||||||
|
when {
|
||||||
|
expression {
|
||||||
|
return params.update_job
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
currentBuild.getRawBuild().getExecutor().interrupt(Result.SUCCESS)
|
||||||
|
sleep(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Prepare inventory') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
def hostsFile = new File("${WORKSPACE}/hosts.ini")
|
||||||
|
hostsFile.append('[all]')
|
||||||
|
hostsFile.append('\n' + params.target_host)
|
||||||
|
println hostsFile.getText('UTF-8')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stage('Add config') {
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
withCredentials([
|
||||||
|
sshUserPrivateKey(credentialsId: 'JENKINS_DEPLOYER_KEY', keyFileVariable: 'SSH_KEY'),
|
||||||
|
usernamePassword(credentialsId:'JENKINS_DEPLOYER_PASS', usernameVariable: 'username', passwordVariable: 'password')
|
||||||
|
]) {
|
||||||
|
wrap([$class: 'MaskPasswordsBuildWrapper', varPasswordPairs: [[password: env.password]]]) {
|
||||||
|
wrap([$class: 'AnsiColorBuildWrapper', colorMapName: "xterm"]) {
|
||||||
|
dir("${env.WORKSPACE}") {
|
||||||
|
ansiblePlaybook(
|
||||||
|
playbook: 'addconfig.yml',
|
||||||
|
inventory: 'hosts.ini',
|
||||||
|
colorized: true,
|
||||||
|
extras: '''--private-key ${SSH_KEY}
|
||||||
|
-e "ansible_user=${username}
|
||||||
|
ansible_password=${password}
|
||||||
|
rproxy_service_name=${rproxy_service_name}
|
||||||
|
rproxy_service_port=${rproxy_service_port}
|
||||||
|
rproxy_service_address=${rproxy_service_address}"'''
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
cleanWs(patterns: [
|
||||||
|
[pattern: 'hosts.ini', type: 'INCLUDE']
|
||||||
|
])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
roles/addconfig/tasks/addconfig.yml
Normal file
5
roles/addconfig/tasks/addconfig.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
- name: Copy server.conf
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: templates/server.conf.j2
|
||||||
|
dest: "{{ rproxy_dir }}/sites/{{ rproxy_service_name }}.conf"
|
||||||
83
roles/addconfig/tasks/certificates.yml
Normal file
83
roles/addconfig/tasks/certificates.yml
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
---
|
||||||
|
- name: Create CNAME dns record
|
||||||
|
community.general.ipa_dnsrecord:
|
||||||
|
ipa_user: "{{ ansible_user }}"
|
||||||
|
ipa_pass: "{{ ansible_password }}"
|
||||||
|
zone_name: "{{ ansible_facts['domain'] }}"
|
||||||
|
record_name: "{{ rproxy_service_name }}"
|
||||||
|
record_type: 'CNAME'
|
||||||
|
record_value: "{{ ansible_facts['hostname'] }}"
|
||||||
|
state: present
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Kinit
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "echo '{{ ansible_password }}' | kinit"
|
||||||
|
become: false
|
||||||
|
become_user: "{{ ansible_user }}"
|
||||||
|
|
||||||
|
- name: Create fake host for certificate
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "ipa host-add {{ rproxy_service_name }}.{{ ansible_facts['domain'] }} --force --desc=\"Fake host for SPN\""
|
||||||
|
become: false
|
||||||
|
become_user: "{{ ansible_user }}"
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Create SPN for HTTP
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "ipa service-add HTTP/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }} --skip-host-check --force"
|
||||||
|
become: false
|
||||||
|
become_user: "{{ ansible_user }}"
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: "Allow {{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }} to get certificates for HTTP/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }} SPN"
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "ipa service-add-host --hosts={{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }} HTTP/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}"
|
||||||
|
become: false
|
||||||
|
become_user: "{{ ansible_user }}"
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Kdestroy
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: kdestroy
|
||||||
|
become: false
|
||||||
|
become_user: "{{ ansible_user }}"
|
||||||
|
|
||||||
|
- name: Get all tracking certificates
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "ipa-getcert list | grep -m1 -B5 \"{{ rproxy_dir }}/certs/{{ rproxy_service_name }}\" | grep Request | awk '{print $NF}' | tr -d \"'\\|:\""
|
||||||
|
register: tracking_list
|
||||||
|
|
||||||
|
- name: Remove certificates from IPA tracking
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "ipa-getcert stop-tracking -i {{ item }}"
|
||||||
|
loop: "{{ tracking_list.stdout_lines }}"
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Request certificate via ipa-getcert
|
||||||
|
ansible.builtin.command: >
|
||||||
|
ipa-getcert request
|
||||||
|
-f {{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.crt
|
||||||
|
-k {{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.key
|
||||||
|
-K HTTP/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}
|
||||||
|
-N CN={{ rproxy_service_name }}.{{ ansible_facts['domain'] }}
|
||||||
|
|
||||||
|
- name: Wait for certificate to appear
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
path: "{{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.crt"
|
||||||
|
timeout: 60
|
||||||
|
|
||||||
|
- name: Change certificate permissions
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.crt"
|
||||||
|
mode: "0744"
|
||||||
|
|
||||||
|
- name: Wait for certificate key to appear
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
path: "{{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.key"
|
||||||
|
timeout: 60
|
||||||
|
|
||||||
|
- name: Change certificate key permissions
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.key"
|
||||||
|
mode: "0744"
|
||||||
14
roles/addconfig/tasks/main.yml
Normal file
14
roles/addconfig/tasks/main.yml
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
- name: Add config
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: addconfig.yml
|
||||||
|
|
||||||
|
- name: Generate certificates
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: certificates.yml
|
||||||
|
|
||||||
|
- name: Restart rproxy service
|
||||||
|
ansible.builtin.systemd:
|
||||||
|
name: "container-rproxy.service"
|
||||||
|
state: restarted
|
||||||
|
enabled: yes
|
||||||
5
roles/addconfig/vars/main.yml
Normal file
5
roles/addconfig/vars/main.yml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
|
|
||||||
|
# Rproxy
|
||||||
|
rproxy_dir: /opt/rproxy
|
||||||
@@ -5,8 +5,6 @@
|
|||||||
- podman
|
- podman
|
||||||
- podman-compose
|
- podman-compose
|
||||||
- podman-docker
|
- podman-docker
|
||||||
- podman-remote
|
|
||||||
- podman-tui
|
|
||||||
- buildah
|
- buildah
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
2
roles/podman/vars/main.yml
Normal file
2
roles/podman/vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
ansible_python_interpreter: /usr/bin/python3
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
---
|
|
||||||
- name: Create server configs
|
|
||||||
block:
|
|
||||||
- name: Copy server.conf
|
|
||||||
ansible.builtin.template:
|
|
||||||
src: templates/server.conf.j2
|
|
||||||
dest: "{{ rproxy_dir }}/sites/{{ rproxy_service_name }}.conf"
|
|
||||||
|
|
||||||
- name: Generate certificates for {{ rproxy_service_name }}
|
|
||||||
block:
|
|
||||||
- name: Create CNAME dns record
|
|
||||||
community.general.ipa_dnsrecord:
|
|
||||||
ipa_user: "{{ ansible_user }}"
|
|
||||||
ipa_pass: "{{ ansible_password }}"
|
|
||||||
zone_name: "{{ ansible_facts['domain'] }}"
|
|
||||||
record_name: "{{ rproxy_service_name }}"
|
|
||||||
record_type: 'CNAME'
|
|
||||||
record_value: "{{ ansible_facts['hostname'] }}"
|
|
||||||
state: present
|
|
||||||
|
|
||||||
- name: Kinit
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: "echo '{{ ansible_password }}' | kinit"
|
|
||||||
become: false
|
|
||||||
become_user: "{{ ansible_user }}"
|
|
||||||
|
|
||||||
- name: Create fake host for certificate
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: "ipa host-add {{ rproxy_service_name }}.{{ ansible_facts['domain'] }} --force --desc=\"Fake host for SPN\""
|
|
||||||
become: false
|
|
||||||
become_user: "{{ ansible_user }}"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Create SPN for HTTP
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: "ipa service-add HTTP/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }} --skip-host-check --force"
|
|
||||||
become: false
|
|
||||||
become_user: "{{ ansible_user }}"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: "Allow {{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }} to get certificates for HTTP/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }} SPN "
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: "ipa service-add-host --hosts={{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }} HTTP/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}"
|
|
||||||
become: false
|
|
||||||
become_user: "{{ ansible_user }}"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Get all tracking certificates
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: ipa-getcert list | grep "ID" | awk '{print $NF}' | tr -d "'\|:"
|
|
||||||
register: tracking_list
|
|
||||||
|
|
||||||
- name: Remove certificates from IPA tracking
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: "ipa-getcert stop-tracking -i {{ item }}"
|
|
||||||
loop: "{{ tracking_list.stdout_lines }}"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Request certificate via ipa-getcert
|
|
||||||
ansible.builtin.command: >
|
|
||||||
ipa-getcert request
|
|
||||||
-f {{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.crt
|
|
||||||
-k {{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.key
|
|
||||||
-K HTTP/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}
|
|
||||||
-N CN={{ rproxy_service_name }}.{{ ansible_facts['domain'] }}
|
|
||||||
|
|
||||||
- name: Wait for certificate to appear
|
|
||||||
ansible.builtin.wait_for:
|
|
||||||
path: "{{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.crt"
|
|
||||||
timeout: 60
|
|
||||||
|
|
||||||
- name: Change certificate permissions
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.crt"
|
|
||||||
mode: "0744"
|
|
||||||
|
|
||||||
- name: Wait for certificate key to appear
|
|
||||||
ansible.builtin.wait_for:
|
|
||||||
path: "{{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.key"
|
|
||||||
timeout: 60
|
|
||||||
|
|
||||||
- name: Change certificate key permissions
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ rproxy_dir }}/certs/{{ rproxy_service_name }}.{{ ansible_facts['domain'] }}.key"
|
|
||||||
mode: "0744"
|
|
||||||
|
|
||||||
- name: Restart rproxy service
|
|
||||||
ansible.builtin.systemd:
|
|
||||||
name: "container-rproxy.service"
|
|
||||||
state: restarted
|
|
||||||
enabled: yes
|
|
||||||
59
roles/rproxy/tasks/certificates.yml
Normal file
59
roles/rproxy/tasks/certificates.yml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
---
|
||||||
|
- name: Kinit
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "echo '{{ ansible_password }}' | kinit"
|
||||||
|
become: false
|
||||||
|
become_user: "{{ ansible_user }}"
|
||||||
|
|
||||||
|
- name: Create SPN for HTTP
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "ipa service-add HTTP/{{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }}"
|
||||||
|
become: false
|
||||||
|
become_user: "{{ ansible_user }}"
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Kdestroy
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: kdestroy
|
||||||
|
become: false
|
||||||
|
become_user: "{{ ansible_user }}"
|
||||||
|
|
||||||
|
- name: Get all tracking certificates
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "ipa-getcert list | grep -m1 -B5 \"{{ rproxy_dir }}/certs/repo\" | grep Request | awk '{print $NF}' | tr -d \"'\\|:\""
|
||||||
|
register: tracking_list
|
||||||
|
|
||||||
|
- name: Remove certificates from IPA tracking
|
||||||
|
ansible.builtin.shell:
|
||||||
|
cmd: "ipa-getcert stop-tracking -i {{ item }}"
|
||||||
|
loop: "{{ tracking_list.stdout_lines }}"
|
||||||
|
ignore_errors: true
|
||||||
|
|
||||||
|
- name: Request certificate via ipa-getcert
|
||||||
|
ansible.builtin.command: >
|
||||||
|
ipa-getcert request
|
||||||
|
-f {{ rproxy_dir }}/certs/repo.crt
|
||||||
|
-k {{ rproxy_dir }}/certs/repo.key
|
||||||
|
-K HTTP/{{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }}
|
||||||
|
-N CN={{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }}
|
||||||
|
-F {{ rproxy_dir }}/certs/RootCA.crt
|
||||||
|
|
||||||
|
- name: Wait for certificate to appear
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
path: "{{ rproxy_dir }}/certs/repo.crt"
|
||||||
|
timeout: 60
|
||||||
|
|
||||||
|
- name: Change certificate permissions
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ rproxy_dir }}/certs/repo.crt"
|
||||||
|
mode: "0744"
|
||||||
|
|
||||||
|
- name: Wait for certificate key to appear
|
||||||
|
ansible.builtin.wait_for:
|
||||||
|
path: "{{ rproxy_dir }}/certs/repo.key"
|
||||||
|
timeout: 60
|
||||||
|
|
||||||
|
- name: Change certificate key permissions
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ rproxy_dir }}/certs/repo.key"
|
||||||
|
mode: "0744"
|
||||||
10
roles/rproxy/tasks/configs.yml
Normal file
10
roles/rproxy/tasks/configs.yml
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
- name: Copy repo.conf
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: files/repo.conf
|
||||||
|
dest: "{{ rproxy_dir }}/sites/repo.conf"
|
||||||
|
|
||||||
|
- name: Copy nginx.conf
|
||||||
|
ansible.builtin.copy:
|
||||||
|
src: files/nginx.conf
|
||||||
|
dest: "{{ rproxy_dir }}/nginx.conf"
|
||||||
31
roles/rproxy/tasks/dirs.yml
Normal file
31
roles/rproxy/tasks/dirs.yml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
---
|
||||||
|
- name: Remove rproxy dir
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ rproxy_dir }}"
|
||||||
|
state: absent
|
||||||
|
|
||||||
|
- name: Create rproxy dir
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ rproxy_dir }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Create rproxy data dir
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ repo_data_dir }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Create sites dir
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ rproxy_dir }}/sites"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Create certs dir
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ rproxy_dir }}/certs"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Create repo dir
|
||||||
|
ansible.builtin.file:
|
||||||
|
path: "{{ repo_data_dir }}"
|
||||||
|
state: directory
|
||||||
|
mode: 0777
|
||||||
@@ -1,32 +1,20 @@
|
|||||||
---
|
---
|
||||||
- name: Podman install
|
- name: Prepare directories
|
||||||
ansible.builtin.include_tasks:
|
ansible.builtin.include_tasks:
|
||||||
file: podman.yml
|
file: dirs.yml
|
||||||
apply:
|
|
||||||
tags: install
|
- name: Copy configs
|
||||||
tags:
|
ansible.builtin.include_tasks:
|
||||||
- install
|
file: configs.yml
|
||||||
|
|
||||||
|
- name: Generate certificates
|
||||||
|
ansible.builtin.include_tasks:
|
||||||
|
file: certificates.yml
|
||||||
|
|
||||||
- name: Rproxy install
|
- name: Rproxy install
|
||||||
ansible.builtin.include_tasks:
|
ansible.builtin.include_tasks:
|
||||||
file: rproxy.yml
|
file: rproxy.yml
|
||||||
apply:
|
|
||||||
tags: install
|
|
||||||
tags:
|
|
||||||
- install
|
|
||||||
|
|
||||||
- name: Repo install
|
- name: Repository install
|
||||||
ansible.builtin.include_tasks:
|
ansible.builtin.include_tasks:
|
||||||
file: repo.yml
|
file: repo.yml
|
||||||
apply:
|
|
||||||
tags: install
|
|
||||||
tags:
|
|
||||||
- install
|
|
||||||
|
|
||||||
- name: Add config
|
|
||||||
ansible.builtin.include_tasks:
|
|
||||||
file: addconfig.yml
|
|
||||||
apply:
|
|
||||||
tags: add_config
|
|
||||||
tags:
|
|
||||||
- add_config
|
|
||||||
@@ -1,78 +1,10 @@
|
|||||||
---
|
---
|
||||||
- name: Prepare for https repository
|
- name: Install createrepo
|
||||||
block:
|
|
||||||
- name: Create repo dir
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ repo_data_dir }}"
|
|
||||||
state: directory
|
|
||||||
mode: 0777
|
|
||||||
|
|
||||||
- name: Copy repo.conf
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: files/repo.conf
|
|
||||||
dest: "{{ rproxy_dir }}/sites/repo.conf"
|
|
||||||
|
|
||||||
- name: Install createrepo
|
|
||||||
ansible.builtin.yum:
|
ansible.builtin.yum:
|
||||||
name:
|
name:
|
||||||
- createrepo
|
- createrepo
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
|
||||||
- name: Create https certificates for repository
|
|
||||||
block:
|
|
||||||
- name: Kinit
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: "echo '{{ ansible_password }}' | kinit"
|
|
||||||
become: false
|
|
||||||
become_user: "{{ ansible_user }}"
|
|
||||||
|
|
||||||
- name: Create SPN for HTTP
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: "ipa service-add HTTP/{{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }}"
|
|
||||||
become: false
|
|
||||||
become_user: "{{ ansible_user }}"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Get all tracking certificates
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: ipa-getcert list | grep "ID" | awk '{print $NF}' | tr -d "'\|:"
|
|
||||||
register: tracking_list
|
|
||||||
|
|
||||||
- name: Remove certificates from IPA tracking
|
|
||||||
ansible.builtin.shell:
|
|
||||||
cmd: "ipa-getcert stop-tracking -i {{ item }}"
|
|
||||||
loop: "{{ tracking_list.stdout_lines }}"
|
|
||||||
ignore_errors: true
|
|
||||||
|
|
||||||
- name: Request certificate via ipa-getcert
|
|
||||||
ansible.builtin.command: >
|
|
||||||
ipa-getcert request
|
|
||||||
-f {{ rproxy_dir }}/certs/repo.crt
|
|
||||||
-k {{ rproxy_dir }}/certs/repo.key
|
|
||||||
-K HTTP/{{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }}
|
|
||||||
-N CN={{ ansible_facts['hostname'] }}.{{ ansible_facts['domain'] }}
|
|
||||||
-F {{ rproxy_dir }}/certs/RootCA.crt
|
|
||||||
|
|
||||||
- name: Wait for certificate to appear
|
|
||||||
ansible.builtin.wait_for:
|
|
||||||
path: "{{ rproxy_dir }}/certs/repo.crt"
|
|
||||||
timeout: 60
|
|
||||||
|
|
||||||
- name: Change certificate permissions
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ rproxy_dir }}/certs/repo.crt"
|
|
||||||
mode: "0744"
|
|
||||||
|
|
||||||
- name: Wait for certificate key to appear
|
|
||||||
ansible.builtin.wait_for:
|
|
||||||
path: "{{ rproxy_dir }}/certs/repo.key"
|
|
||||||
timeout: 60
|
|
||||||
|
|
||||||
- name: Change certificate key permissions
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ rproxy_dir }}/certs/repo.key"
|
|
||||||
mode: "0744"
|
|
||||||
|
|
||||||
- name: Restart rproxy service
|
- name: Restart rproxy service
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: "container-rproxy.service"
|
name: "container-rproxy.service"
|
||||||
|
|||||||
@@ -1,49 +1,15 @@
|
|||||||
---
|
---
|
||||||
- name: Prepare dirs for rproxy
|
- name: Pull rproxy image
|
||||||
block:
|
|
||||||
- name: Remove rproxy dir
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ rproxy_dir }}"
|
|
||||||
state: absent
|
|
||||||
|
|
||||||
- name: Create rproxy dir
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ rproxy_dir }}"
|
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: Create rproxy data dir
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ repo_data_dir }}"
|
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: Create sites dir
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ rproxy_dir }}/sites"
|
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: Create certs dir
|
|
||||||
ansible.builtin.file:
|
|
||||||
path: "{{ rproxy_dir }}/certs"
|
|
||||||
state: directory
|
|
||||||
|
|
||||||
- name: Copy nginx.conf
|
|
||||||
ansible.builtin.copy:
|
|
||||||
src: files/nginx.conf
|
|
||||||
dest: "{{ rproxy_dir }}/nginx.conf"
|
|
||||||
|
|
||||||
- name: Install rproxy
|
|
||||||
block:
|
|
||||||
- name: Pull rproxy image
|
|
||||||
containers.podman.podman_image:
|
containers.podman.podman_image:
|
||||||
name: "{{ image_repo }}/{{ rproxy_image }}:{{ rproxy_version }}"
|
name: "{{ image_repo }}/{{ rproxy_image }}:{{ rproxy_version }}"
|
||||||
state: present
|
state: present
|
||||||
|
|
||||||
- name: Delete rproxy container if exists
|
- name: Delete rproxy container if exists
|
||||||
containers.podman.podman_container:
|
containers.podman.podman_container:
|
||||||
name: rproxy
|
name: rproxy
|
||||||
state: absent
|
state: absent
|
||||||
|
|
||||||
- name: Start rproxy
|
- name: Start rproxy
|
||||||
containers.podman.podman_container:
|
containers.podman.podman_container:
|
||||||
name: rproxy
|
name: rproxy
|
||||||
image: "{{ image_repo }}/{{ rproxy_image }}:{{ rproxy_version }}"
|
image: "{{ image_repo }}/{{ rproxy_image }}:{{ rproxy_version }}"
|
||||||
@@ -68,7 +34,7 @@
|
|||||||
stop_timeout: 120
|
stop_timeout: 120
|
||||||
names: true
|
names: true
|
||||||
|
|
||||||
- name: Enable rproxy service
|
- name: Enable rproxy service
|
||||||
ansible.builtin.systemd:
|
ansible.builtin.systemd:
|
||||||
name: "container-rproxy.service"
|
name: "container-rproxy.service"
|
||||||
state: started
|
state: started
|
||||||
|
|||||||
16
rproxy.yml
16
rproxy.yml
@@ -2,25 +2,11 @@
|
|||||||
- hosts: all
|
- hosts: all
|
||||||
become: yes
|
become: yes
|
||||||
|
|
||||||
vars:
|
|
||||||
ansible_python_interpreter: /usr/bin/python3
|
|
||||||
|
|
||||||
vars_prompt:
|
vars_prompt:
|
||||||
- name: rproxy_service_name
|
|
||||||
prompt: Enter service for rproxy
|
|
||||||
private: false
|
|
||||||
|
|
||||||
- name: rproxy_service_port
|
|
||||||
prompt: Enter service for rproxy
|
|
||||||
private: false
|
|
||||||
|
|
||||||
- name: rproxy_service_address
|
|
||||||
prompt: Enter service for rproxy
|
|
||||||
private: false
|
|
||||||
|
|
||||||
- name: image_repo
|
- name: image_repo
|
||||||
prompt: Enter repository address with podman images (ex. rproxy.olsson.ul:5000)
|
prompt: Enter repository address with podman images (ex. rproxy.olsson.ul:5000)
|
||||||
private: false
|
private: false
|
||||||
|
|
||||||
roles:
|
roles:
|
||||||
|
- podman
|
||||||
- rproxy
|
- rproxy
|
||||||
|
|||||||
Reference in New Issue
Block a user