--- - 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.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' # Base installation directory the Go language SDK distribution golang_install_dir: '/usr/local/go' # Directory to store files downloaded for Go language SDK installation golang_download_dir: "{{ x_ansible_download_dir | default(ansible_env.HOME + '/.ansible/tmp/downloads') }}" # Location for GOPATH environment variable golang_gopath: "/home/{{ user }}/go" # Filename of Go language SDK redistributable package golang_redis_filename: 'go{{ golang_version }}.linux-amd64.tar.gz' ############################################################### # CGRateS vars cgrates_dir: "{{ golang_gopath }}/src/github.com/cgrates/cgrates" cgrates_branch: "1.0" cgrates_distribution: "nightly" ############################################################### ######################## GPG Vars ############################# ############################################################### gpg_home: "/root" gpg_realname: "CGRateS" gpg_useremail: "cgrates@itsyscom.com" gpg_pubkeyfileexport: "apt.cgrates.org.gpg.key" gpg_keylength: 2048 gpg_subkeylength: 2048 gpg_expire: 360 rootUser : root customPath: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}" dependencies: - build-essential - git - devscripts - reprepro - nginx remote_user: '{{ user }}' tasks: - name: set cgrates cgrates_distribution set_fact: cgrates_distribution: "{{ cgrates_distribution }}" ########################################################################################################################### ########################################################################################################################### # install dependencies - name: Install dependencies become: yes apt: name={{ dependencies }} state=present ########################################################################################################################### ########################################################################################################################### # Prepare for configuration - name: Config reprepro include: reprepro.yaml - name: Generate GPG Key include: gpg.yaml - name: Check if NGINX needs to be configured become: true shell: "ls /etc/nginx/sites-enabled | grep 'apt.cgrates.org.vhost'" ignore_errors: true register: nginxConfig - 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 Golang - name: install unarchive dependencies (zypper) become: yes zypper: name: - gzip - tar state: present when: ansible_pkg_mgr == 'zypper' - name: Install golang include: go.yaml ########################################################################################################################### ########################################################################################################################### # Install CGRateS - name: create cgrates directory become: yes file: state: directory mode: 'u=rwx,go=rx' owner: "{{ user }}" group: "{{ user }}" dest: '{{ cgrates_dir }}' become_user: "{{ user }}" - name: git clone cgrates git: repo: https://github.com/cgrates/cgrates.git dest: '{{ cgrates_dir }}' update: yes force: yes version: "{{ cgrates_branch }}" become: yes become_user: "{{ user }}" - name: clean go cache 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 become: yes shell: "go clean --modcache" 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 shell: "sh {{ cgrates_dir }}/build.sh" environment: PATH: "{{ lookup('env','PATH') }}:{{ golang_gopath }}/bin:/usr/local/go/bin:{{ ansible_env.PATH }}" args: 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 }}' register: gitTagVar ########################################################################################################################### ########################################################################################################################### # Generate package - name: Generate package become: yes command: 'sudo env "PATH={{ customPath }}" make deb' args: chdir: '{{ cgrates_dir }}/packages' - name: Check if the package was generated become: yes shell: "sudo ls {{ golang_gopath }}/src/github.com/cgrates | grep 'cgrates_'" ignore_errors: true register: packageVar - name: Move the files to /var/packages/debian/incoming become: yes command: sudo mv {{item}} /var/packages/debian/incoming/ args: chdir: '{{ golang_gopath }}/src/github.com/cgrates' when : packageVar.stdout_lines|length > 0 with_items: '{{ packageVar.stdout_lines }}' - name : Get the name of the deb file become: yes shell : "sudo ls /var/packages/debian/incoming/ | grep '.deb'" register: debFileName - name : Get the name of the changes file become: yes shell : "sudo ls /var/packages/debian/incoming/ | grep '.changes'" register: changesFileNames # 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 become: yes command: sudo reprepro -A amd64 -Vb . include {{ cgrates_distribution }} /var/packages/debian/incoming/{{ item }} ignore_errors: true args : chdir: /var/packages/debian 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/' args: chdir: /var/packages/debian/incoming/ with_items: '{{ debFileName.stdout_lines }}' # Clean the incoming folder - name: Clean the incoming folder become: yes shell: "sudo rm /var/packages/debian/incoming/*" args: 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 set_fact: cgrates_distribution: "{{ hostvars['apt']['cgrates_distribution'] }}" - name: Creates directory become: yes 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 - name: Move the new package to /var/packages/deb become: yes shell: "mv /tmp/{{ item}} /var/packages/deb/{{ cgrates_distribution }}/" with_items: "{{ hostvars['apt']['debFileName']['stdout_lines'] }}" - name: Create the new symlink cgrates_current_amd64.deb become: yes file: src: /var/packages/deb/{{ cgrates_distribution }}/{{ item }} 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