From 662223743a22e6d08a8771b0807be0a3c5610412 Mon Sep 17 00:00:00 2001 From: Tadas Tamosauskas Date: Fri, 13 Dec 2019 12:43:02 +0000 Subject: [PATCH] Allow uninstalling or reinstalling based on variables This is a backwards compatible change - behaviour remains unchanged when it's run with default variables. However this allows uninstalling or reinstalling ffmpeg and ffprobe when variables reinstall_ffmpeg or uninstall_ffmpeg are set to 'true' wither in `vars` section of the playbook or via extra vars e.g. --extra-vars "reinstall_ffmpeg=true" --- README.md | 8 ++++++- defaults/main.yml | 8 ++++++- tasks/install.yml | 56 +++++++++++++++++++++++++++++++++++++++++++ tasks/main.yml | 58 ++++----------------------------------------- tasks/uninstall.yml | 7 ++++++ 5 files changed, 81 insertions(+), 56 deletions(-) create mode 100644 tasks/install.yml create mode 100644 tasks/uninstall.yml diff --git a/README.md b/README.md index fb89e07..e277a7e 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,12 @@ ffmpeg_executable_path: "/usr/bin/ffmpeg" # The final path of ffprobe executable ffprobe_executable_path: "/usr/bin/ffprobe" + +# Whether to uninstall ffmpeg and ffprobe +uninstall_ffmpeg: 'false' + +# Whether to reinstall ffmpeg and ffprobe when they exist +reinstall_ffmpeg: 'false' ``` Dependencies @@ -47,4 +53,4 @@ MIT Author Information ------------------ -[Hedi Chaibi](https://hedichaibi.com) \ No newline at end of file +[Hedi Chaibi](https://hedichaibi.com) diff --git a/defaults/main.yml b/defaults/main.yml index 93c8dc6..4327a84 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -6,4 +6,10 @@ ffmpeg_temp_path: /tmp/ffmpeg ffmpeg_executable_path: /usr/bin/ffmpeg # The final path of ffprobe executable -ffprobe_executable_path: /usr/bin/ffprobe \ No newline at end of file +ffprobe_executable_path: /usr/bin/ffprobe + +# Whether to uninstall ffmpeg and ffprobe +uninstall_ffmpeg: 'false' + +# Whether to reinstall ffmpeg and ffprobe when they exist +reinstall_ffmpeg: 'false' diff --git a/tasks/install.yml b/tasks/install.yml new file mode 100644 index 0000000..8e7edb6 --- /dev/null +++ b/tasks/install.yml @@ -0,0 +1,56 @@ +--- +- name: Check if ffmpeg is already installed + stat: + path: "{{ ffmpeg_executable_path }}" + register: ffmpeg_bin + +- name: Check if ffprobe is already installed + stat: + path: "{{ ffprobe_executable_path }}" + register: ffprobe_bin + +- name: Create a temp directory + file: + path: "{{ ffmpeg_temp_path }}" + state: directory + when: (not ffmpeg_bin.stat.exists) or + (not ffprobe_bin.stat.exists) + +- name: Download from custom source + get_url: + url: https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz + dest: "{{ ffmpeg_temp_path }}/ffmpeg-git-amd64-static.tar.xz" + when: (not ffmpeg_bin.stat.exists) or + (not ffprobe_bin.stat.exists) + +- name: Unarchive to temp directory + shell: tar xf {{ ffmpeg_temp_path }}/ffmpeg-git-amd64-static.tar.xz --strip-components=1 -C {{ ffmpeg_temp_path }}/ + when: (not ffmpeg_bin.stat.exists) or + (not ffprobe_bin.stat.exists) + +- name: Move ffmpeg to executables directory + command: mv {{ ffmpeg_temp_path }}/ffmpeg {{ ffmpeg_executable_path }} + args: + creates: "{{ ffmpeg_executable_path }}" + +- name: Move ffprobe to executables directory + command: mv {{ ffmpeg_temp_path }}/ffprobe {{ ffprobe_executable_path }} + args: + creates: "{{ ffprobe_executable_path }}" + +- name: Make ffmpeg executable by all users + file: + path: "{{ ffmpeg_executable_path }}" + mode: 0755 + when: not ffmpeg_bin.stat.exists + +- name: Make ffprobe executable by all users + file: + path: "{{ ffprobe_executable_path }}" + mode: 0755 + when: not ffprobe_bin.stat.exists + +- name: Delete temp directory + file: + path: "{{ ffmpeg_temp_path }}" + state: absent diff --git a/tasks/main.yml b/tasks/main.yml index 8e7edb6..f0ea97d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,56 +1,6 @@ ---- -- name: Check if ffmpeg is already installed - stat: - path: "{{ ffmpeg_executable_path }}" - register: ffmpeg_bin +- include: uninstall.yml + when: uninstall_ffmpeg == 'true' or reinstall_ffmpeg == 'true' -- name: Check if ffprobe is already installed - stat: - path: "{{ ffprobe_executable_path }}" - register: ffprobe_bin +- include: install.yml + when: uninstall_ffmpeg != 'true' -- name: Create a temp directory - file: - path: "{{ ffmpeg_temp_path }}" - state: directory - when: (not ffmpeg_bin.stat.exists) or - (not ffprobe_bin.stat.exists) - -- name: Download from custom source - get_url: - url: https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-amd64-static.tar.xz - dest: "{{ ffmpeg_temp_path }}/ffmpeg-git-amd64-static.tar.xz" - when: (not ffmpeg_bin.stat.exists) or - (not ffprobe_bin.stat.exists) - -- name: Unarchive to temp directory - shell: tar xf {{ ffmpeg_temp_path }}/ffmpeg-git-amd64-static.tar.xz --strip-components=1 -C {{ ffmpeg_temp_path }}/ - when: (not ffmpeg_bin.stat.exists) or - (not ffprobe_bin.stat.exists) - -- name: Move ffmpeg to executables directory - command: mv {{ ffmpeg_temp_path }}/ffmpeg {{ ffmpeg_executable_path }} - args: - creates: "{{ ffmpeg_executable_path }}" - -- name: Move ffprobe to executables directory - command: mv {{ ffmpeg_temp_path }}/ffprobe {{ ffprobe_executable_path }} - args: - creates: "{{ ffprobe_executable_path }}" - -- name: Make ffmpeg executable by all users - file: - path: "{{ ffmpeg_executable_path }}" - mode: 0755 - when: not ffmpeg_bin.stat.exists - -- name: Make ffprobe executable by all users - file: - path: "{{ ffprobe_executable_path }}" - mode: 0755 - when: not ffprobe_bin.stat.exists - -- name: Delete temp directory - file: - path: "{{ ffmpeg_temp_path }}" - state: absent diff --git a/tasks/uninstall.yml b/tasks/uninstall.yml new file mode 100644 index 0000000..110eb76 --- /dev/null +++ b/tasks/uninstall.yml @@ -0,0 +1,7 @@ +- name: Uninstall old ffmpeg and ffprobe + file: + path: "{{ item }}" + state: absent + with_items: + - "{{ ffmpeg_executable_path }}" + - "{{ ffprobe_executable_path }}"