mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-18 09:04:26 -04:00
consolidate ansible setup into roles dir
This commit is contained in:
parent
25db6826ec
commit
c55cd46ecb
27 changed files with 763 additions and 91 deletions
|
@ -0,0 +1,31 @@
|
|||
---
|
||||
argument_specs:
|
||||
main:
|
||||
short_description: Load a specified binary from the environment/PATH into BINARIES fact.
|
||||
|
||||
options:
|
||||
|
||||
name:
|
||||
type: "str"
|
||||
required: true
|
||||
description: "A string key for the binary"
|
||||
|
||||
bin_name:
|
||||
type: "str"
|
||||
required: false
|
||||
description: "The basename of the binary file (optional, defaults to name)"
|
||||
|
||||
abspath:
|
||||
type: "str"
|
||||
required: false
|
||||
description: "An absolute path to the binary (overrides any auto-detected one)"
|
||||
|
||||
version_cmd:
|
||||
type: "str"
|
||||
required: false
|
||||
description: "The command to run to get the binary's version (optional, defaults to $ <bin_name> --version)"
|
||||
|
||||
PATH:
|
||||
type: "str"
|
||||
required: false
|
||||
description: "The PATH to search for the binary (optional, defaults to environment $PATH)"
|
73
archivebox/builtin_plugins/ansible/roles/load_binary/tasks/main.yml
Executable file
73
archivebox/builtin_plugins/ansible/roles/load_binary/tasks/main.yml
Executable file
|
@ -0,0 +1,73 @@
|
|||
|
||||
---
|
||||
- name: Make sure ./data/lib/bin folder exists
|
||||
file:
|
||||
path: '{{LIB_DIR_BIN}}'
|
||||
state: directory
|
||||
recurse: true
|
||||
|
||||
###################################################################################
|
||||
|
||||
- set_fact:
|
||||
PATH: "{{PATH or DEFAULT_PATH}}"
|
||||
bin_name: "{{bin_name or name}}"
|
||||
BINARY_ABSPATH: null
|
||||
BINARY_VERSION: null
|
||||
|
||||
- name: 'Get installed binary abspath: {{name}}'
|
||||
command: 'env PATH="{{PATH}}:$PATH" which {{bin_name}}'
|
||||
register: BINARY_ABSPATH
|
||||
changed_when: BINARIES[name].abspath|default('NO VERSION FOUND') not in BINARY_ABSPATH.stdout
|
||||
|
||||
- set_fact:
|
||||
bin_name: "{{BINARY_ABSPATH.stdout|basename or bin_name}}"
|
||||
- set_fact:
|
||||
version_cmd: "{{version_cmd or (bin_name + ' --version')}}"
|
||||
|
||||
- name: 'Get installed binary version: {{name}}'
|
||||
command: 'env PATH="{{PATH}}:$PATH" {{version_cmd}}'
|
||||
register: BINARY_VERSION
|
||||
changed_when: BINARIES[name].version|default('NO VERSION FOUND') not in BINARY_VERSION.stdout
|
||||
|
||||
|
||||
- name: 'Updating BINARIES with loaded abspaths & versions: {{name}}'
|
||||
set_fact:
|
||||
BINARIES: "{{ BINARIES
|
||||
| default({})
|
||||
| combine({
|
||||
name: {
|
||||
'name': name,
|
||||
'bin_name': bin_name,
|
||||
'version_cmd': version_cmd,
|
||||
'symlink': LIB_DIR_BIN + '/' + name,
|
||||
'abspath': BINARY_ABSPATH.stdout or abspath or None,
|
||||
'version': BINARY_VERSION.stdout_lines|first|regex_replace('^.*?([\\d+\\.]+).*$', '\\1') or version or None,
|
||||
'version_stdout': BINARY_VERSION.stdout or BINARY_VERSION.stderr,
|
||||
'PATH': BINARY_ABSPATH.stdout|dirname or PATH,
|
||||
},
|
||||
})
|
||||
}}"
|
||||
cacheable: true
|
||||
when: BINARY_ABSPATH.stdout and BINARY_VERSION.stdout
|
||||
|
||||
- name: 'Symlink installed binary into lib bin folder: {{name}}'
|
||||
file:
|
||||
src: "{{ BINARY_ABSPATH.stdout }}"
|
||||
dest: "{{ LIB_DIR_BIN }}/{{ name }}"
|
||||
state: link
|
||||
force: true
|
||||
when: BINARY_ABSPATH.stdout and BINARY_VERSION.stdout
|
||||
changed_when: False
|
||||
|
||||
- debug:
|
||||
msg:
|
||||
- '{{BINARIES}}'
|
||||
|
||||
- name: Unset variables
|
||||
set_fact:
|
||||
name:
|
||||
bin_name:
|
||||
version_cmd:
|
||||
PATH:
|
||||
BINARY_ABSPATH:
|
||||
BINARY_VERSION:
|
|
@ -0,0 +1,11 @@
|
|||
DATA_DIR: '{{playbook_dir}}'
|
||||
LIB_DIR: '{{DATA_DIR}}/lib'
|
||||
LIB_DIR_BIN: '{{LIB_DIR}}/bin'
|
||||
DEFAULT_PATH: /bin
|
||||
|
||||
name:
|
||||
bin_name:
|
||||
version_cmd:
|
||||
PATH:
|
||||
abspath:
|
||||
version:
|
Loading…
Add table
Add a link
Reference in a new issue