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

chore: if binary_file_name_override is defined, ensure it exists with proper permissions #33

Merged
merged 1 commit into from
Jan 15, 2025
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Lint yaml and Ansible configs
run: |
python -m pip install --upgrade pip
pip install ansible-lint==24.6.0 yamllint==1.35.1
pip install ansible-lint==24.12.2 yamllint==1.35.1
yamllint --config-file ./tests/yaml-lint.yml .
ansible-lint --config-file ./tests/ansible-lint.yml .
molecule:
Expand Down
17 changes: 8 additions & 9 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@
command:
# sleep infinity

cpus: 100
memory: 1G

ports: {}
# example-port1:
# ingressPort: 80
# servicePort: 2411
# example-port2:
# ingressPort: 443
# servicePort: 2412
setup_iptables: false

config: {}
# example-config1:
Expand Down Expand Up @@ -52,36 +56,31 @@
# appPath: /app/data

restart_policy: on-failure
uninstall: false
volume_list: []
port_list: []

uninstall: false

### Container ###
image:
network_mode: bridge

### Systemd ###
binary_url:
binary_strip_components: 0

# (Optional) Override the binary file name after moving it to the destination directory
# binary_file_name_override:

cpus: 100
memory: 1G

systemd: {}
# service_type: e.g. simple, oneshot, forking (https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html#Type=)

Check warning on line 76 in defaults/main.yml

View workflow job for this annotation

GitHub Actions / lint

76:121 [line-length] line too long (130 > 120 characters)
# unit_properties: {}
# service_properties: {}
# install_properties: {}

systemd_environment_directive: ""
binary_strip_components: 0

### Kubernetes ###
helm_chart_path: ../../helm
helm_namespace: default
helm_values_path: values.yml

###

setup_iptables: false
64 changes: 33 additions & 31 deletions tasks/common/download-binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,46 @@
state: directory
mode: "0755"

- name: Set Binary file name based on URL
- name: Set binary file name based on URL
ansible.builtin.set_fact:
binary_file_name: "{{ binary_url | basename }}"
binary_file_path: "/tmp/{{ binary_url | basename }}"
target_binary_path: "{{ destination_directory }}/{{ binary_file_name_override | default(binary_url | basename) }}"

- name: Download the binary file
ansible.builtin.get_url:
url: "{{ binary_url }}"
dest: /tmp/{{ binary_file_name }}
dest: "{{ binary_file_path }}"
mode: "0755"

- name: Unarchive the file if it's an archive
ansible.builtin.unarchive:
src: /tmp/{{ binary_file_name }}
dest: "{{ destination_directory }}"
remote_src: true
extra_opts:
- "--strip-components={{ binary_strip_components }}"
when: >
binary_file_name.endswith('.tar') or binary_file_name.endswith('.tar.gz') or
binary_file_name.endswith('.tgz') or binary_file_name.endswith('.zip')
- name: Handle binary file based on type
block:
- name: Unarchive the file if it's an archive
ansible.builtin.unarchive:
src: "{{ binary_file_path }}"
dest: "{{ destination_directory }}"
remote_src: true
extra_opts:
- "--strip-components={{ binary_strip_components }}"
when: binary_file_name | regex_search('\.(tar|tar\.gz|tgz|zip)$')

- name: Move the file if it's not an archive
ansible.builtin.command: >
mv /tmp/{{ binary_file_name }} {{ destination_directory }}/{{ binary_file_name_override | default(binary_file_name) }}
when: >
not (binary_file_name.endswith('.tar') or
binary_file_name.endswith('.tar.gz') or
binary_file_name.endswith('.tgz') or
binary_file_name.endswith('.zip'))
register: mv_output
changed_when: mv_output.rc != 0
- name: Move the file if it's not an archive
ansible.builtin.command: >
mv {{ binary_file_path }} {{ target_binary_path }}
register: mv_output
changed_when: mv_output.rc != 0
when: not (binary_file_name | regex_search('\.(tar|tar\.gz|tgz|zip)$'))

- name: Ensure the file has executable permissions
ansible.builtin.file:
path: "{{ destination_directory }}/{{ binary_file_name_override | default(binary_file_name) }}"
mode: "0755"
when: >
not (binary_file_name.endswith('.tar') or
binary_file_name.endswith('.tar.gz') or
binary_file_name.endswith('.tgz') or
binary_file_name.endswith('.zip'))
- name: Check if the binary override file exists
ansible.builtin.stat:
path: "{{ destination_directory }}/{{ binary_file_name_override }}"
register: binary_override_file_stat
when:
- binary_file_name_override is defined

- name: Fail if the binary override file does not exist
ansible.builtin.fail:
msg: "The binary file does not exist at {{ destination_directory }}/{{ binary_file_name_override }}."
when:
- binary_file_name_override is defined
- not binary_override_file_stat.stat.exists
2 changes: 1 addition & 1 deletion tests/ansible-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ exclude_paths:
- ../.git/
- ../.github
- ../helm/
- ../test/
- ./*
warn_list:
- experimental
1 change: 1 addition & 0 deletions tests/molecule/systemd-full/converge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
user: root
binary_url: https://github.com/prometheus/prometheus/releases/download/v2.47.0/prometheus-2.47.0.linux-amd64.tar.gz
binary_strip_components: 1
binary_file_name_override: prometheus # set to trigger existence of extracted binary check
destination_directory: /usr/bin
command: /usr/bin/prometheus --config.file=/test/mnt/etc/prometheus/prometheus.yml
cpus: 50
Expand Down
2 changes: 1 addition & 1 deletion tests/yaml-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ignore: |
.git/
.github/
helm/
test/
tests/molecule
rules:
line-length:
max: 120
Expand Down
Loading