Updated ansible scripts

This commit is contained in:
Trial97
2021-07-23 10:59:58 +03:00
committed by Dan Christian Bogos
parent 1daa13b91b
commit 6112db9aa3
11 changed files with 95 additions and 131 deletions

View File

@@ -1,11 +1,12 @@
---
- hosts: all
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.16.5'
golang_version: '1.16.6'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'

View File

@@ -1,11 +1,12 @@
---
- hosts: all
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.16.3'
golang_version: '1.16.6'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'

View File

@@ -1,11 +1,12 @@
---
- hosts: all
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.16.3'
golang_version: '1.16.6'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'

View File

@@ -1,35 +1,12 @@
---
- name: Check and set python version on APT server
hosts: apt
remote_user: '{{ user }}'
gather_facts: false
tasks:
- name: symlink /usr/bin/python -> /usr/bin/python3
raw: |
if [ -f /usr/bin/python3 ] && [ ! -f /usr/bin/python ]; then
ln --symbolic /usr/bin/python3 /usr/bin/python;
fi
become: true
- name: Check and set python version on PKG server
hosts: pkg
remote_user: '{{ user }}'
gather_facts: false
tasks:
- name: symlink /usr/bin/python -> /usr/bin/python3
raw: |
if [ -f /usr/bin/python3 ] && [ ! -f /usr/bin/python ]; then
ln --symbolic /usr/bin/python3 /usr/bin/python;
fi
become: true
- hosts: apt
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.16.3'
golang_version: '1.16.6'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'
@@ -45,7 +22,7 @@
###############################################################
# CGRateS vars
cgrates_dir: "{{ golang_gopath }}/src/github.com/cgrates/cgrates"
cgrates_branch: "master"
cgrates_branch: "1.0"
cgrates_distribution: "nightly"
###############################################################
######################## GPG Vars #############################
@@ -241,6 +218,8 @@
chdir: /var/packages/debian
- hosts: pkg
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
remote_user: '{{ user }}'
tasks:
- name: set cgrates cgrates_distribution

View File

@@ -43,19 +43,19 @@
- name: Creates directory
become: yes
file:
path: /var/docker/registry
path: /var/docker/{{ registry_name }}
state: directory
- name: Check if registry is running
become: yes
shell: docker container ls -q -f="name=registry"
shell: docker container ls -q -f="name=^{{ registry_name }}$"
register: continerList
- name: Start registry
become: yes
shell: docker run -d --name registry --restart=always -v "$(pwd)":/var/lib/registry -p 5000:5000 registry:2
shell: docker run -d --name {{ registry_name }} --restart=always -v "$(pwd)":/var/lib/{{ registry_name }} -p 5000:5000 registry:2
args:
chdir: /var/docker/registry
chdir: /var/docker/{{ registry_name }}
when: continerList.stdout_lines|length == 0

View File

@@ -1,23 +1,12 @@
---
- name: Check and set python version on APT server
hosts: dkr
remote_user: '{{ user }}'
gather_facts: false
tasks:
- name: symlink /usr/bin/python -> /usr/bin/python3
raw: |
if [ -f /usr/bin/python3 ] && [ ! -f /usr/bin/python ]; then
ln --symbolic /usr/bin/python3 /usr/bin/python;
fi
become: true
- hosts: dkr
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.16.3'
golang_version: '1.16.6'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'
@@ -33,9 +22,12 @@
###############################################################
# CGRateS vars
cgrates_dir: "{{ golang_gopath }}/src/github.com/cgrates/cgrates"
cgrates_branch: "master"
cgrates_branch: "1.0"
cgrates_distribution: "nightly"
docker_tag: "latest"
registry_site: "dkr.cgrates.org" # the web site
registry_name: "registry" # the name of the registry container
users_filename: "" # the file containing the htpasswd users
dependencies:
- build-essential
@@ -50,6 +42,15 @@
- python3-pip
- virtualenv
- python3-setuptools
- apache2-utils
build_execs:
- cgr-engine
- cgr-console
- cgr-loader
- cgr-migrator
- cgr-tester
rootUser : root
remote_user: '{{ user }}'
@@ -57,7 +58,7 @@
- name: set cgrates distribution
set_fact:
cgrates_distribution: "{{ cgrates_branch }}"
when: cgrates_branch != "master"
when: cgrates_branch != "master" or cgrates_branch != "1.0"
###########################################################################################################################
###########################################################################################################################
# install dependencies
@@ -69,13 +70,13 @@
# Prepare for configuration
- name: Check if NGINX needs to be configured
become: true
shell: "ls /etc/nginx/sites-enabled | grep 'dkr.cgrates.org.vhost'"
shell: "ls /etc/nginx/sites-enabled | grep '{{ registry_site }}.vhost'"
ignore_errors: true
register: nginxConfig
- name: Configure NGINX server
include: nginx.yaml
when: nginxConfig.stdout_lines|length < 1
when: nginxConfig.stdout_lines|length < 1 or users_filename|length > 0
- name: Configure docker
include: docker.yaml
@@ -130,14 +131,6 @@
environment:
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
- name: sync the go mod with vendor
become: yes
shell: "go mod vendor"
environment:
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
args:
chdir: '{{ cgrates_dir }}'
- name: build cgrates for docker
shell: "sh {{ cgrates_dir }}/data/docker/scratch/build.sh"
environment:
@@ -145,6 +138,18 @@
args:
chdir: '{{ cgrates_dir }}/data/docker/scratch'
- name: clean go cache after build
become: yes
shell: "go clean --cache"
environment:
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
- name: clean go modcache after build
become: yes
shell: "go clean --modcache"
environment:
PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
- name: copy certificate authority
copy:
remote_src: yes
@@ -162,71 +167,53 @@
args:
chdir: '{{ cgrates_dir }}'
register: gitCommit
when: cgrates_branch == "master" or gitTagVar.stdout_lines|length == 0
when: cgrates_branch == "master" or cgrates_branch == "1.0" or gitTagVar.stdout_lines|length == 0
- name: get commit
shell: date +%Y%m%d%H%M%S --date="@$(git log -n1 --format=format:%ct)"
args:
chdir: '{{ cgrates_dir }}'
register: gitDate
when: cgrates_branch == "master" or gitTagVar.stdout_lines|length == 0
when: cgrates_branch == "master" or cgrates_branch == "1.0" or gitTagVar.stdout_lines|length == 0
- name: set cgrates docker_tag
set_fact:
docker_tag: "{{ gitDate.stdout }}{{ gitCommit.stdout }}"
when: cgrates_branch == "master" or gitTagVar.stdout_lines|length == 0
when: cgrates_branch == "master" or cgrates_branch == "1.0" or gitTagVar.stdout_lines|length == 0
- name: build Docker image
become: yes
shell:
docker build -t 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-engine:{{ docker_tag }} -f="cgr-engine.doker" {{ cgrates_dir }}/data/docker/scratch/;
docker build -t 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-console:{{ docker_tag }} -f="cgr-console.doker" {{ cgrates_dir }}/data/docker/scratch/;
docker build -t 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-loader:{{ docker_tag }} -f="cgr-loader.doker" {{ cgrates_dir }}/data/docker/scratch/;
docker build -t 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-migrator:{{ docker_tag }} -f="cgr-migrator.doker" {{ cgrates_dir }}/data/docker/scratch/;
docker build -t 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-tester:{{ docker_tag }} -f="cgr-tester.doker" {{ cgrates_dir }}/data/docker/scratch/;
docker build -t 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }} -f="{{ item }}.doker" {{ cgrates_dir }}/data/docker/scratch/;
args:
chdir: '{{ cgrates_dir }}/data/docker/scratch'
with_items: "{{ build_execs }}"
- name: push docker image to repo
become: yes
shell:
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-engine:{{ docker_tag }};
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-console:{{ docker_tag }};
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-loader:{{ docker_tag }};
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-migrator:{{ docker_tag }};
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-tester:{{ docker_tag }};
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }};
with_items: "{{ build_execs }}"
- name: tag docker master image
become: yes
shell:
docker tag 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-engine:{{ docker_tag }} 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-engine:latest;
docker tag 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-console:{{ docker_tag }} 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-console:latest;
docker tag 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-loader:{{ docker_tag }} 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-loader:latest;
docker tag 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-migrator:{{ docker_tag }} 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-migrator:latest;
docker tag 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-tester:{{ docker_tag }} 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-tester:latest;
when: cgrates_branch == "master"
docker tag 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:{{ docker_tag }} 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:latest;
when: cgrates_branch == "master" or cgrates_branch == "1.0"
with_items: "{{ build_execs }}"
- name: push docker master image to repo
become: yes
shell:
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-engine:latest;
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-console:latest;
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-loader:latest;
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-migrator:latest;
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/cgr-tester:latest;
when: cgrates_branch == "master"
docker image push 127.0.0.1:5000/{{ cgrates_distribution }}/{{ item }}:latest;
when: cgrates_branch == "master" or cgrates_branch == "1.0"
with_items: "{{ build_execs }}"
- name: clean binar files
file:
path: "{{ cgrates_dir }}/data/docker/scratch/{{ item }}"
state: absent
with_items:
- cgr-engine
- cgr-console
- cgr-loader
- cgr-migrator
- cgr-tester
with_items: "{{ build_execs }}"
- name: remove local docker images
become: yes

View File

@@ -6,10 +6,13 @@ map $upstream_http_docker_distribution_api_version $docker_distribution_api_vers
server {
listen 80;
autoindex_localtime on;
server_name dkr.cgrates.org;
server_name {{ registry_site }};
access_log /var/log/nginx/docker-error.log;
error_log /var/log/nginx/docker-error.log;
# disable any limits to avoid HTTP 413 for large image uploads
client_max_body_size 0;
# required to avoid HTTP 411: see Issue #1486 (https://github.com/moby/moby/issues/1486)
chunked_transfer_encoding on;
@@ -24,9 +27,11 @@ server {
# To add basic authentication to v2 use auth_basic setting.
limit_except GET HEAD OPTIONS {
deny all;
# auth_basic "Registry realm";
# auth_basic_user_file /etc/nginx/conf.d/nginx.htpasswd;
}
{% if users_filename|length > 0 %}
auth_basic "Registry realm";
auth_basic_user_file /etc/nginx/conf.d/nginx.htpasswd;
{% endif %}
## If $docker_distribution_api_version is empty, the header is not added.
## See the map directive above where this variable is defined.

View File

@@ -1,24 +1,36 @@
---
- name: Add users
become: true
template:
src: "{{ users_filename }}"
dest: "/etc/nginx/conf.d/nginx.htpasswd"
mode: '0644'
owner: "{{ rootUser }}"
when: users_filename|length > 0
- name: Delete default page
become: true
file:
path: "/etc/nginx/sites-enabled/default"
state: absent
when: nginxConfig.stdout_lines|length < 1
- name: Add apt.cgrates.vhost in nginx
- name: Add {{ registry_site }}.vhost in nginx
become: true
template:
src: nginx.conf.j2
dest: "/etc/nginx/sites-available/dkr.cgrates.org.vhost"
dest: "/etc/nginx/sites-available/{{ registry_site }}.vhost"
mode: '0600'
owner: "{{ rootUser }}"
when: nginxConfig.stdout_lines|length < 1
- name: Create a symlink for docker.cgrates.org
- name: Create a symlink for {{ registry_site }}
become: true
file:
src: "/etc/nginx/sites-available/dkr.cgrates.org.vhost"
dest: "/etc/nginx/sites-enabled/dkr.cgrates.org.vhost"
src: "/etc/nginx/sites-available/{{ registry_site }}.vhost"
dest: "/etc/nginx/sites-enabled/{{ registry_site }}.vhost"
state: link
when: nginxConfig.stdout_lines|length < 1
- name: Restart the nginx so the change take effects
become: true

View File

@@ -1,23 +1,12 @@
---
- name: Check and set python version on APT server
hosts: ci
remote_user: '{{ user }}'
gather_facts: false
tasks:
- name: symlink /usr/bin/python -> /usr/bin/python3
raw: |
if [ -f /usr/bin/python3 ] && [ ! -f /usr/bin/python ]; then
ln --symbolic /usr/bin/python3 /usr/bin/python;
fi
become: true
- hosts: ci
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.16.3'
golang_version: '1.16.6'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'

View File

@@ -1,11 +1,12 @@
---
- hosts: local
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.16.3'
golang_version: '1.16.6'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'
@@ -56,11 +57,7 @@
become: yes
apt:
name: redis-server
# - name: Install the mongo
# apt:
# name: mongodb-server
- name: Install the mysql
become: yes
apt:

View File

@@ -1,22 +1,12 @@
- name: Check and set python version on PKG server
hosts: pkg
remote_user: '{{ user }}'
gather_facts: false
tasks:
- name: symlink /usr/bin/python -> /usr/bin/python3
raw: |
if [ -f /usr/bin/python3 ] && [ ! -f /usr/bin/python ]; then
ln --symbolic /usr/bin/python3 /usr/bin/python;
fi
become: true
---
- hosts: yum
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
###############################################################
##################### Golang Vars #############################
###############################################################
# Go language SDK version number
golang_version: '1.16.3'
golang_version: '1.16.6'
go_version_target: "go version go{{ golang_version }} linux/amd64"
# Mirror to download the Go language SDK redistributable package from
golang_mirror: 'https://storage.googleapis.com/golang'
@@ -32,7 +22,7 @@
###############################################################
# CGRateS location
cgrates_dir: "{{ golang_gopath }}/src/github.com/cgrates/cgrates"
cgrates_branch: "master"
cgrates_branch: "1.0"
cgrates_distribution: "nightly"
###############################################################
##################### GPG Vars #############################
@@ -318,6 +308,8 @@
shell: "sudo chcon -t httpd_sys_rw_content_t /var/packages/ -R"
- hosts: pkg
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
remote_user: '{{ user }}'
tasks:
- name: set cgrates cgrates_distribution