Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transplant from koelslaw/AYR #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
transplant from koelslaw/AYR
  • Loading branch information
koelslaw committed Apr 16, 2020
commit 92ec2b2244e9b8a742e08f0303b55001aee53378
8 changes: 8 additions & 0 deletions ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[defaults]
roles_path = ./roles
inventory = ./hosts/
host_key_checking = False
retry_files_enabled = False

[ssh_connection]
ssh_args = -o ControlMaster=auto -o ControlPersist=300s -o ForwardAgent=yes
1 change: 1 addition & 0 deletions ansible/group_vars/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
# This should contain default variables that are for the entire project
# across all roles, groups, and hosts. Overrides should be done in
# a `globals.yml` located in the projects configuration dir (i.e. /etc/servus/globals)
vars_files_relative: ".."
24 changes: 24 additions & 0 deletions ansible/site.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# vim: set ft=ansible
# site.yml
---
# add any additional mirrors if you need to otherwise leave default so it will only deploy on localhost
- hosts: repo_mirrors
become: true
vars_files:
- "./vars/main.yml"
tasks:
- include: prepare_system.yml
tags:
- prepare_system
- include: create_mirror.yml
tags:
- create_mirror
- include: prepare_cron.yml
when: repo_autosync|bool == True
tags:
- prepare_cron
- include: remove_cron.yml
when: repo_autosync|bool == False
tags:
- prepare_cron

13 changes: 13 additions & 0 deletions create_mirror.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
- block:
- name: Create folder for the mirror
file:
path: "/var/www/html/{{ item['folder'] }}"
state: directory
mode: 0755
with_items: "{{ mirrors }}"

- name: Execute repository creation script
script: "./scripts/create_repo.sh {{ item['folder'] }} {{ item['items']|join(',') }}"
with_items: "{{ mirrors }}"

become: true
11 changes: 11 additions & 0 deletions prepare_cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
- name: Prepare cronjob for autosync
cron:
day: "{{ crontab_day }}"
hour: "{{ crontab_hour }}"
minute: "{{ crontab_minute }}"
month: "{{ crontab_month }}"
weekday: "{{ crontab_weekday }}"
name: "Cronjob to autosync repo"
state: present
job: "sudo ansible-playbook ~/ayr/site.yml --tags=create_mirror -i ~/ayr/hosts.ini > /dev/null"
become: true
37 changes: 37 additions & 0 deletions prepare_system.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
- block:
- name: Install needed packages for reposync
package:
name: "{{ item }}"
state: present
with_items:
- createrepo
- yum-utils
- httpd

- name: Install needed packaged for firewalld
package:
name: "{{ item }}"
state: present
with_items:
- python-firewall

- name: Check if firewalld is running
command: systemctl is-active firewalld
ignore_errors: yes
changed_when: false
register: firewalld_service_status

- name: Open firewall port for http (firewall)
firewalld:
service: http
permanent: true
state: enabled
immediate: true
when: firewalld_service_status.stdout == 'active'

- name: Create directory to contain mirrors
file:
path: "/var/www/html"
state: directory
mode: 0755
become: true
5 changes: 5 additions & 0 deletions remove_cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
- name: Remove cronjob for autosync
cron:
name: "Cronjob to autosync repo"
state: absent
become: true
32 changes: 32 additions & 0 deletions scripts/create_repo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
REPO_FOLDER=$1
REPO_ITEMS=$2

REPOPATH="/var/www/html/"
REPOFILE="${REPOPATH}/${REPO_FOLDER}/local.repo"

mkdir -p $REPOPATH
rm $REPOFILE 2> /dev/null
touch $REPOFILE

echo "${REPOPATH}${REPO_FOLDER}"

for i in $(echo $REPO_ITEMS | sed "s/,/ /g")
do
reposync -n -l --repoid=$i --download_path=/var/www/html/general_mirror/ --downloadcomps --download-metadata
wait

createrepo -v /var/www/html/general_mirror/$i -g comps.xml
wait
done

for DIR in `find ${REPOPATH}/general_mirror/ -maxdepth 1 -mindepth 1 -type d`; do
REPO_ITEM=$(basename $DIR)
if [[ "${REPO_ITEMS}" =~ "${REPO_ITEM}" ]]; then
echo -e "[${REPO_ITEM}]" >> $REPOFILE
echo -e "name=${REPO_ITEM}" >> $REPOFILE
echo -e "baseurl=http://[your.ip.or.url.goes.here]/general_mirror/${REPO_ITEM}/" >> $REPOFILE
echo -e "enabled=1" >> $REPOFILE
echo -e "gpgcheck=0" >> $REPOFILE
echo -e "\n" >> $REPOFILE
fi
done;
17 changes: 17 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repo_autosync: false
crontab_day: '*'
crontab_hour: '*'
crontab_minute: '*'
crontab_month: '*'
crontab_weekday: '*'
mirrors:
- name: rhel.repo
folder: general_mirror
items:
- rhel-7-server-rpms
- rhel-7-server-extras-rpms
- rhel-7-server-rh-common-rpms
- rhel-ha-for-rhel-7-server-rpms
- epel
- group_rocknsm-rocknsm-2.1
- atomic