Skip to content

Commit

Permalink
Resolve permission issue in deb_packages playbook
Browse files Browse the repository at this point in the history
  • Loading branch information
ionutboangiu authored and danbogos committed Jul 21, 2023
1 parent 2b0be04 commit 189e6d5
Showing 1 changed file with 47 additions and 48 deletions.
95 changes: 47 additions & 48 deletions data/ansible/deb_packages/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
gpg_subkeylength: 2048
gpg_expire: 360

rootUser : root
rootUser: root

customPath: "{{ lookup('env','PATH') }}:/home/{{ user }}/go/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"

Expand All @@ -28,20 +28,20 @@
- reprepro
- nginx

remote_user: '{{ user }}'
remote_user: "{{ user }}"
tasks:
- name: set cgrates cgrates_distribution
set_fact:
cgrates_distribution: "{{ cgrates_distribution }}"
###########################################################################################################################
###########################################################################################################################
# install dependencies
###########################################################################################################################
###########################################################################################################################
# install dependencies
- name: Install dependencies
become: yes
apt: name={{ dependencies }} state=present
###########################################################################################################################
###########################################################################################################################
# Prepare for configuration
###########################################################################################################################
###########################################################################################################################
# Prepare for configuration
- name: Config reprepro
include: reprepro.yaml

Expand All @@ -57,38 +57,38 @@
- name: Configure NGINX server
include: nginx.yaml
when: nginxConfig.stdout_lines|length < 1

- name: Enable and start nginx
systemd:
name: nginx
state: started
masked: no
enabled: yes

###########################################################################################################################
###########################################################################################################################
# Install Go
###########################################################################################################################
###########################################################################################################################
# Install Go
- name: Install Go
import_role:
name: ../roles/install_go

###########################################################################################################################
###########################################################################################################################
# Install CGRateS
###########################################################################################################################
###########################################################################################################################
# Install CGRateS
- name: create cgrates directory
become: yes
file:
state: directory
mode: 'u=rwx,go=rx'
mode: "u=rwx,go=rx"
owner: "{{ user }}"
group: "{{ user }}"
dest: '{{ cgrates_dir }}'
dest: "{{ cgrates_dir }}"
become_user: "{{ user }}"

- name: git clone cgrates
git:
repo: https://github.com/cgrates/cgrates.git
dest: '{{ cgrates_dir }}'
dest: "{{ cgrates_dir }}"
update: yes
force: yes
version: "{{ cgrates_branch }}"
Expand All @@ -113,35 +113,34 @@
environment:
PATH: "{{ lookup('env','PATH') }}:/home/{{ user }}/go/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
args:
chdir: '{{ cgrates_dir }}'
chdir: "{{ cgrates_dir }}"

- name: build cgrates
- name: build cgrates
shell: "sh {{ cgrates_dir }}/build.sh"
environment:
PATH: "{{ lookup('env','PATH') }}:/home/{{ user }}/go/bin:/usr/local/go/bin:{{ ansible_env.PATH }}"
args:
chdir: '{{ cgrates_dir }}'
chdir: "{{ cgrates_dir }}"

- name: symbol link
become: yes
file:
src: "{{ cgrates_dir }}/data"
dest: "/usr/share/cgrates"
state: link

- name: get git tag
shell: "git tag -l --points-at HEAD"
args:
chdir: '{{ cgrates_dir }}'
chdir: "{{ cgrates_dir }}"
register: gitTagVar
###########################################################################################################################
###########################################################################################################################
# Generate package
- name: Generate package
become: yes
###########################################################################################################################
###########################################################################################################################
# Generate package
- name: Generate package
command: 'sudo env "PATH={{ customPath }}" make deb'
args:
chdir: '{{ cgrates_dir }}/packages'
chdir: "{{ cgrates_dir }}/packages"

- name: Check if the package was generated
become: yes
Expand All @@ -153,42 +152,42 @@
become: yes
command: sudo mv {{item}} /var/packages/debian/incoming/
args:
chdir: '/home/{{ user }}/go/src/github.com/cgrates'
when : packageVar.stdout_lines|length > 0
with_items: '{{ packageVar.stdout_lines }}'
chdir: "/home/{{ user }}/go/src/github.com/cgrates"
when: packageVar.stdout_lines|length > 0
with_items: "{{ packageVar.stdout_lines }}"

- name : Get the name of the deb file
- name: Get the name of the deb file
become: yes
shell : "sudo ls /var/packages/debian/incoming/ | grep '.deb'"
shell: "sudo ls /var/packages/debian/incoming/ | grep '.deb'"
register: debFileName

- name : Get the name of the changes file
- name: Get the name of the changes file
become: yes
shell : "sudo ls /var/packages/debian/incoming/ | grep '.changes'"
shell: "sudo ls /var/packages/debian/incoming/ | grep '.changes'"
register: changesFileNames

# get reprepro version
# get reprepro version
- name: set cgrates distribution
set_fact:
cgrates_distribution: "{{ cgrates_branch }}"
when: cgrates_branch != "master"

# Include the package with reprepro
- name : Include the package with reprepro
# Include the package with reprepro
- name: Include the package with reprepro
become: yes
command: sudo reprepro -A amd64 -Vb . include {{ cgrates_distribution }} /var/packages/debian/incoming/{{ item }}
ignore_errors: true
args :
args:
chdir: /var/packages/debian
with_items: '{{ changesFileNames.stdout_lines }}'
when : cgrates_branch == "master" or gitTagVar.stdout_lines|length > 0
with_items: "{{ changesFileNames.stdout_lines }}"
when: cgrates_branch == "master" or gitTagVar.stdout_lines|length > 0

# Move the file to PKG server
- name: Copy the file to PKG server
shell: 'scp /var/packages/debian/incoming/{{ item }} {{ pkgAddr }}:/tmp/'
shell: "scp /var/packages/debian/incoming/{{ item }} {{ pkgAddr }}:/tmp/"
args:
chdir: /var/packages/debian/incoming/
with_items: '{{ debFileName.stdout_lines }}'
with_items: "{{ debFileName.stdout_lines }}"

# Clean the incoming folder
- name: Clean the incoming folder
Expand All @@ -200,7 +199,7 @@
- hosts: pkg
vars:
ansible_python_interpreter: auto # to disable deprication warning related to the use of python2
remote_user: '{{ user }}'
remote_user: "{{ user }}"
tasks:
- name: set cgrates cgrates_distribution
set_fact:
Expand All @@ -211,13 +210,13 @@
file:
path: /var/packages/deb/{{ cgrates_distribution }}/
state: directory

- name: Remove symlink from current deb package
become: yes
file:
path: /var/packages/deb/{{ cgrates_distribution }}/cgrates_current_amd64.deb
state: absent
when : cgrates_distribution == "nightly" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
when: cgrates_distribution == "nightly" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0

- name: Move the new package to /var/packages/deb
become: yes
Expand All @@ -231,4 +230,4 @@
dest: /var/packages/deb/{{ cgrates_distribution }}/cgrates_current_amd64.deb
state: link
with_items: "{{ hostvars['apt']['debFileName']['stdout_lines'] }}"
when : cgrates_distribution == "nightly" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0
when: cgrates_distribution == "nightly" or hostvars['apt']['gitTagVar'].stdout_lines|length > 0

0 comments on commit 189e6d5

Please sign in to comment.