From 8bba489c3d13594c61420aaf68376a635c5abbae Mon Sep 17 00:00:00 2001 From: ionutboangiu Date: Fri, 11 Jul 2025 20:08:48 +0300 Subject: [PATCH] ansible: add cgrates_deb_install playbook --- data/ansible/cgrates_deb_install/README.md | 28 ++++++ .../ansible/cgrates_deb_install/inventory.ini | 17 ++++ data/ansible/cgrates_deb_install/main.yaml | 92 +++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 data/ansible/cgrates_deb_install/README.md create mode 100644 data/ansible/cgrates_deb_install/inventory.ini create mode 100644 data/ansible/cgrates_deb_install/main.yaml diff --git a/data/ansible/cgrates_deb_install/README.md b/data/ansible/cgrates_deb_install/README.md new file mode 100644 index 000000000..82a36fe59 --- /dev/null +++ b/data/ansible/cgrates_deb_install/README.md @@ -0,0 +1,28 @@ +# CGRates Package Installation + +Installs CGRates 1.0 from deb package and configures from private GitHub repo. + +## Setup + +1. Configure `inventory.ini` with your server and GitHub details +2. Run: `ansible-playbook -i inventory.ini main.yaml` + +SSH keys auto-generated. Set `github_ssh_use_deploy_keys=true` for repo-specific access. + +## Repository Structure + +``` +config-repo/ +├── node1/ +│ ├── etc/ +│ │ └── cgrates/ +│ │ └── cgrates.json +│ └── tp/ +└── node2/ + ├── etc/ + │ └── cgrates/ + └── tp/ +``` + +The playbook clones the repo to `/opt/{repo-name}` and creates symlinks: +- `/etc/cgrates` → `/opt/{repo-name}/node1/etc/cgrates` diff --git a/data/ansible/cgrates_deb_install/inventory.ini b/data/ansible/cgrates_deb_install/inventory.ini new file mode 100644 index 000000000..e518f0a1e --- /dev/null +++ b/data/ansible/cgrates_deb_install/inventory.ini @@ -0,0 +1,17 @@ +[cgrates_server] +# Add your server IP or hostname here +# Example: +# cgrates-server ansible_host=192.168.1.100 ansible_user=user1 + +[cgrates_server:vars] +# GitHub repository settings (might wanna encrypt these with ansible-vault) +vault_github_token=your_github_personal_access_token_here +vault_github_repo_owner=your_github_username_or_org +vault_github_repo_name=your_private_config_repo_name + +# Configuration source path in repository +vault_cgrates_config_source_path=node_test/etc/cgrates + +# SSH key configuration (optional) +# github_ssh_use_deploy_keys=false +# github_ssh_deploy_key_read_only=false diff --git a/data/ansible/cgrates_deb_install/main.yaml b/data/ansible/cgrates_deb_install/main.yaml new file mode 100644 index 000000000..6eccb99e6 --- /dev/null +++ b/data/ansible/cgrates_deb_install/main.yaml @@ -0,0 +1,92 @@ +--- +- name: Install CGRates from deb package and configure from private repository + hosts: all + become: true + vars: + # Configuration repository settings + cgrates_config_repo: "git@github.com:{{ vault_github_repo_owner }}/{{ vault_github_repo_name }}.git" + cgrates_config_source_path: "{{ vault_cgrates_config_source_path }}" + cgrates_repo_dir: "/opt/{{ vault_github_repo_name }}" + + tasks: + - name: Install CGRates from deb package + ansible.builtin.import_role: + name: ../roles/cgrates + vars: + cgrates_install_method: "package" + cgrates_package_version: "1.0" + cgrates_debian_codename: "bookworm" + + - name: Set up GitHub SSH access + ansible.builtin.import_role: + name: ../roles/github_ssh + vars: + github_ssh_token: "{{ vault_github_token }}" + github_ssh_repo_owner: "{{ vault_github_repo_owner }}" + github_ssh_repo_name: "{{ vault_github_repo_name }}" + when: + - vault_github_token is defined + - vault_github_repo_owner is defined + - vault_github_repo_name is defined + + - name: Configuration deployment + block: + - name: Create repository directory + ansible.builtin.file: + path: "{{ cgrates_repo_dir }}" + state: directory + owner: "{{ ansible_user }}" + group: "{{ ansible_user }}" + mode: '0755' + + - name: Clone configuration repository + ansible.builtin.git: + repo: "{{ cgrates_config_repo }}" + dest: "{{ cgrates_repo_dir }}" + force: true + update: true + become_user: "{{ ansible_user }}" + notify: restart cgrates + + - name: Check if source path exists in repository + ansible.builtin.stat: + path: "{{ cgrates_repo_dir }}/{{ cgrates_config_source_path }}" + register: config_source_stat + + - name: Deploy configuration via symlink + when: config_source_stat.stat.exists + block: + - name: Check if /etc/cgrates is already a symlink + ansible.builtin.stat: + path: "/etc/cgrates" + register: cgrates_dest_stat + + - name: Remove existing /etc/cgrates directory if not a symlink + ansible.builtin.file: + path: "/etc/cgrates" + state: absent + when: cgrates_dest_stat.stat.exists and not cgrates_dest_stat.stat.islnk + + - name: Create symlink to configuration + ansible.builtin.file: + src: "{{ cgrates_repo_dir }}/{{ cgrates_config_source_path }}" + dest: "/etc/cgrates" + state: link + force: true + notify: restart cgrates + + - name: Display configuration source + ansible.builtin.debug: + msg: "Configuration linked from {{ cgrates_repo_dir }}/{{ cgrates_config_source_path }} to /etc/cgrates" + + - name: Skip configuration when source path doesn't exist + ansible.builtin.debug: + msg: "Source path '{{ cgrates_config_source_path }}' not found in repository, skipping configuration" + when: not config_source_stat.stat.exists + + handlers: + - name: restart cgrates + ansible.builtin.systemd: + name: cgrates + state: restarted + daemon_reload: true