diff --git a/README.md b/README.md index 93e7e18..730b72f 100644 --- a/README.md +++ b/README.md @@ -50,20 +50,26 @@ Variables used in the `build` installation process. - **wkhtmltopdf_architecture**: architecture (`i386` or `amd64`). - **wkhtmltopdf_build**: method to download software (`tarball`, `git`). - **wkhtmltopdf_build_args**: argument to be passed to `build.py` in order to build the software. -- **wkhtmltopdf_build_dependencies**: list of packages needed to build the software. - **wkhtmltopdf_chroot_args**: argument to be passed to `build.py` in order to setup the chroot environment. +- **wkhtmltopdf_default_version**: flag to indicate if this version is the default one. - **wkhtmltopdf_dir_chroot**: directory to setup chroot environment. - **wkhtmltopdf_dir_source**: directory where to store the source tarball. - **wkhtmltopdf_dir_source_version**: directory where to extract the tarball or clone the git repository. -- **wkhtmltopdf_download_url**: URL to download tarball. +- **wkhtmltopdf_source_dependencies**: list of packages needed to build the software. +- **wkhtmltopdf_tarball_download_url**: URL to download tarball. - **wkhtmltopdf_force_build**: . - **wkhtmltopdf_slug**: git repository slug to be cloned. - **wkhtmltopdf_tarball**: tarball basename. +### package + +- **wkhtmltopdf_package_download_url**: URL to download debian package. + + ## Dependencies -- [ansiblebit/git] +- [ansiblebit/git] if you want to install using `wkhtmltopdf_installation=source` and `wkhtmltopdf_build=git` ## Playbooks @@ -110,7 +116,8 @@ For `git`: wkhtmltopdf_installation: source roles: - - role: ansiblebit.wkhtmltopdf + - role: ansiblebit.git + - role: ansiblebit.wkhtmltopdf ## Tags diff --git a/defaults/main.yml b/defaults/main.yml index cf04ee5..540b0db 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -9,3 +9,33 @@ wkhtmltopdf_user: "{{ ansible_env.USER }}" wkhtmltopdf_version: 0.12.4 wkhtmltopdf_mm_version: "{{ '.'.join(wkhtmltopdf_version.split('.')[0:2]) }}" + + +## package + +wkhtmltopdf_package: "wkhtmltox-{{ wkhtmltopdf_version }}_linux-{{ ansible_distribution_release }}-{{ (ansible_architecture == 'x86_64') | ternary('amd64', 'i386') }}.deb" +wkhtmltopdf_package_download_url: "http://download.gna.org/wkhtmltopdf/{{ wkhtmltopdf_mm_version }}/{{ wkhtmltopdf_version }}/{{ wkhtmltopdf_package }}" + + +## source + +wkhtmltopdf_architecture: amd64 + +wkhtmltopdf_build_args: "linux-generic-{{ wkhtmltopdf_architecture }}" + +wkhtmltopdf_chroot_args: setup-schroot-generic + +wkhtmltopdf_default_version: yes +wkhtmltopdf_dir_chroot: /var/chroot +wkhtmltopdf_dir_source: "{{ ansible_env.HOME }}" +wkhtmltopdf_dir_source_version: "{{ wkhtmltopdf_dir_source }}/wkhtmltox-{{ wkhtmltopdf_version }}" + +wkhtmltopdf_force_build: no + +wkhtmltopdf_source_dependencies: + - xorg + +wkhtmltopdf_slug: wkhtmltopdf/wkhtmltopdf + +wkhtmltopdf_tarball: "wkhtmltox-{{ wkhtmltopdf_version }}.tar.bz2" +wkhtmltopdf_tarball_download_url: "http://download.gna.org/wkhtmltopdf/{{ wkhtmltopdf_mm_version }}/{{ wkhtmltopdf_version }}/{{ wkhtmltopdf_tarball }}" diff --git a/meta/main.yml b/meta/main.yml index 6485a7d..41acc06 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -21,7 +21,4 @@ galaxy_info: - precise galaxy_tags: - wkhtmltopdf -dependencies: - - role: ansiblebit.git - when: wkhtmltopdf_installation == 'source' and - wkhtmltopdf_build == 'git' +dependencies: [] diff --git a/tasks/debug.yml b/tasks/debug.yml index 8a686d1..ea97119 100644 --- a/tasks/debug.yml +++ b/tasks/debug.yml @@ -12,21 +12,3 @@ - wkhtmltopdf_installation - wkhtmltopdf_mm_version - wkhtmltopdf_version - -- name: debug build variables - debug: - var="{{ item }}" - when: "{{ wkhtmltopdf_installation }} == 'build' and {{ item }} is defined" - with_items: - - wkhtmltopdf_architecture - - wkhtmltopdf_build - - wkhtmltopdf_build_dependencies - - wkhtmltopdf_dir_chroot - - wkhtmltopdf_dir_install - - wkhtmltopdf_dir_source - - wkhtmltopdf_dir_source_version - - wkhtmltopdf_download_url - - wkhtmltopdf_force_build - - wkhtmltopdf_slug - - wkhtmltopdf_tarball - - wkhtmltopdf_user diff --git a/tasks/main.yml b/tasks/main.yml index 43c2bc3..a2e852d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -9,7 +9,22 @@ - include: validation.yml tags: validation -- include_vars: "{{ wkhtmltopdf_installation }}.yml" +- name: is wkhtmltopdf installed? => task_installed + shell: /bin/which wkhtmltopdf + register: task_installed + changed_when: no + failed_when: no + environment: + PATH: "${PATH}:{{ wkhtmltopdf_dir_install }}/bin" + +- name: desired version is installed? => task_already_installed + shell: "wkhtmltopdf --version | grep 'wkhtmltopdf {{ wkhtmltopdf_version }} (with patched qt)'" + when: (task_installed is defined and task_installed.rc == 0) + register: task_already_installed + changed_when: no + failed_when: no - include: "{{ wkhtmltopdf_installation }}/main.yml" + when: (task_installed is defined and task_installed.rc != 0) or + (task_already_installed is defined and task_already_installed.rc != 0) tags: installation diff --git a/tasks/package/debug.yml b/tasks/package/debug.yml new file mode 100644 index 0000000..f35852b --- /dev/null +++ b/tasks/package/debug.yml @@ -0,0 +1,13 @@ +--- +# file: wkhtmltopdf/tasks/package/debug.yml +# +# debug tasks. +# + +- name: debug package variables + debug: + var="{{ item }}" + when: "{{ item }} is defined" + with_items: + - wkhtmltopdf_package + - wkhtmltopdf_package_download_url diff --git a/tasks/package/main.yml b/tasks/package/main.yml index 93eee80..f1756e9 100644 --- a/tasks/package/main.yml +++ b/tasks/package/main.yml @@ -4,19 +4,16 @@ # tasks to install wkhtmltopdf using package. # -- name: package | ensure wkhtmltopdf_installation package is possible for wkhtmltopdf_version - fail: - msg="wkhtmltopdf_installation package only possible on 0.12.2 and 0.12.1" - when: wkhtmltopdf_version != '0.12.2' and wkhtmltopdf_version != '0.12.1' +- include: debug.yml + when: debug | default(false) + tags: debug -- name: package | ensure wkhtmltopdf_installation package is possible for distribution version - fail: - msg="wkhtmltopdf_installation package only possible on ubuntu/trusty+precise or debian/wheezy" - when: wkhtmltopdf_installation == 'package' and ansible_distribution_release not in ['precise', 'trusty', 'wheezy' ] +- include: validation.yml + tags: validation - name: package | download get_url: - url="{{ wkhtmltopdf_download_url }}" + url="{{ wkhtmltopdf_package_download_url }}" dest="{{ ansible_env.HOME }}/{{ wkhtmltopdf_package }}" owner="{{ wkhtmltopdf_user }}" group="{{ wkhtmltopdf_user }}" diff --git a/tasks/package/validation.yml b/tasks/package/validation.yml new file mode 100644 index 0000000..5b3838f --- /dev/null +++ b/tasks/package/validation.yml @@ -0,0 +1,23 @@ +--- +# file: wkhtmltopdf/tasks/package/validation.yml +# +# validation tasks. +# + +- name: package | ensure wkhtmltopdf_installation package is possible for wkhtmltopdf_version + fail: + msg="wkhtmltopdf_installation package only possible on 0.12.2 and 0.12.1" + when: wkhtmltopdf_version != '0.12.2' and wkhtmltopdf_version != '0.12.1' + +- name: package | ensure wkhtmltopdf_installation package is possible for distribution version + fail: + msg="wkhtmltopdf_installation package only possible on ubuntu/trusty+precise or debian/wheezy" + when: wkhtmltopdf_installation == 'package' and ansible_distribution_release not in ['precise', 'trusty', 'wheezy' ] + +- name: build | ensure build mandatory variables are set + fail: + msg="{{ item }} is a mandatory variable" + when: "{{ item }} is not defined" + with_items: + - wkhtmltopdf_package + - wkhtmltopdf_package_download_url diff --git a/tasks/source/debug.yml b/tasks/source/debug.yml new file mode 100644 index 0000000..9234a10 --- /dev/null +++ b/tasks/source/debug.yml @@ -0,0 +1,26 @@ +--- +# file: wkhtmltopdf/tasks/build/debug.yml +# +# debug tasks. +# + +- name: debug build variables + debug: + var="{{ item }}" + when: "{{ item }} is defined" + with_items: + - wkhtmltopdf_architecture + - wkhtmltopdf_build + - wkhtmltopdf_build_args + - wkhtmltopdf_chroot_args + - wkhtmltopdf_default_version + - wkhtmltopdf_dir_chroot + - wkhtmltopdf_dir_install + - wkhtmltopdf_dir_source + - wkhtmltopdf_dir_source_version + - wkhtmltopdf_force_build + - wkhtmltopdf_source_dependencies + - wkhtmltopdf_slug + - wkhtmltopdf_tarball + - wkhtmltopdf_tarball_download_url + - wkhtmltopdf_user diff --git a/tasks/source/main.yml b/tasks/source/main.yml index 3108fd6..a6de5b3 100644 --- a/tasks/source/main.yml +++ b/tasks/source/main.yml @@ -4,35 +4,33 @@ # tasks to install wkhtmltopdf using source. # -- name: build | ensure build mandatory variables are set - fail: - msg="{{ item }} is a mandatory variable" - when: "{{ item }} is not defined" - with_items: - - wkhtmltopdf_architecture - - wkhtmltopdf_build - - wkhtmltopdf_build_args - - wkhtmltopdf_build_dependencies - - wkhtmltopdf_chroot_args - - wkhtmltopdf_dir_chroot - - wkhtmltopdf_dir_install - - wkhtmltopdf_dir_source - - wkhtmltopdf_dir_source_version - - wkhtmltopdf_download_url - - wkhtmltopdf_force_build - - wkhtmltopdf_slug - - wkhtmltopdf_tarball +- include: debug.yml + when: debug | default(false) + tags: debug + +- include: validation.yml + tags: validation + +- name: build | is this desired version installed? => task_version_installed + shell: "test -e {{ wkhtmltopdf_dir_install }}/wkhtmltopdf-{{ wkhtmltopdf_version }}" + register: task_version_installed + changed_when: no + failed_when: no - name: build | install build dependencies action: "{{ ansible_pkg_mgr }} name={{ item }} state=present" - with_items: - - "{{ wkhtmltopdf_build_dependencies }}" become: yes + when: (task_version_installed is defined and task_version_installed.rc != 0) + with_items: + - "{{ wkhtmltopdf_source_dependencies }}" -- include: "{{ wkhtmltopdf_build }}.yml" +- name: build | download and install source (using tarball or git) + include: "{{ wkhtmltopdf_build }}.yml" + when: (task_version_installed is defined and task_version_installed.rc != 0) - name: build | setup chroot environment - shell: "scripts/build.py {{ wkhtmltopdf_chroot_args }}" + shell: "python2.7 scripts/build.py {{ wkhtmltopdf_chroot_args }}" + when: (task_version_installed is defined and task_version_installed.rc != 0) register: task_setup_chroot changed_when: not task_setup_chroot.stdout.find('skipped') args: @@ -42,7 +40,8 @@ become: yes - name: build | build binaries - shell: "scripts/build.py { wkhtmltopdf_build_args }}" + shell: "python2.7 scripts/build.py {{ wkhtmltopdf_build_args }}" + when: (task_version_installed is defined and task_version_installed.rc != 0) register: task_build changed_when: not task_build.stdout.find('Nothing to be done') args: @@ -52,22 +51,22 @@ become_user: "{{ wkhtmltopdf_user }}" become: yes -- name: build | copy binaries +- name: build | install version specific binaries copy: - src="{{ wkhtmltopdf_dir_source_version }}/static-build/linux-generic-{{ wkhtmltopdf_architecture }}/app/bin/{{ item }}" - dest="{{ wkhtmltopdf_dir_install }}" + src="{{ wkhtmltopdf_dir_source_version }}/static-build/linux-generic-{{ wkhtmltopdf_architecture }}/app/bin/{{ item.src }}" + dest="{{ wkhtmltopdf_dir_install }}/{{ item.dest }}" remote_src=yes owner=root group=root mode=0755 become: yes + when: (task_version_installed is defined and task_version_installed.rc != 0) with_items: - - wkhtmltoimage - - wkhtmltopdf - - "libwkhtmltox.so.{{ wkhtmltopdf_version }}" - become: yes + - { src: 'wkhtmltoimage', dest: "wkhtmltoimage-{{ wkhtmltopdf_version }}" } + - { src: 'wkhtmltopdf', dest: "wkhtmltopdf-{{ wkhtmltopdf_version }}" } + - { src: "libwkhtmltox.so.{{ wkhtmltopdf_version }}", dest: "libwkhtmltox.so.{{ wkhtmltopdf_version }}" } -- name: build | create symlinks +- name: build | create default version symlinks file: src="{{ wkhtmltopdf_dir_install }}/{{ item.src }}" dest="{{ wkhtmltopdf_dir_install }}/{{ item.dest }}" @@ -75,8 +74,8 @@ group=root state=link become: yes + when: wkhtmltopdf_default_version with_items: - - { src: "libwkhtmltox.so.{{ wkhtmltopdf_version }}", dest: "libwkhtmltox.so.{{ wkhtmltopdf_version.split('.')[0] }}" } - - { src: "libwkhtmltox.so.{{ wkhtmltopdf_version }}", dest: "libwkhtmltox.so.{{ '.'.join(wkhtmltopdf_version.split('.')[0:2]) }}" } - - { src: 'wkhtmltopdf', dest: "wkhtmltopdf-{{ wkhtmltopdf_version }}" } - - { src: 'wkhtmltoimage', dest: "wkhtmltoimage-{{ wkhtmltopdf_version }}" } + - { src: "wkhtmltopdf-{{ wkhtmltopdf_version }}", dest: 'wkhtmltopdf' } + - { src: "wkhtmltoimage-{{ wkhtmltopdf_version }}", dest: 'wkhtmltoimage' } + - { src: "libwkhtmltox.so.{{ wkhtmltopdf_version }}", dest: 'libwkhtmltox.so' } diff --git a/tasks/source/tarball.yml b/tasks/source/tarball.yml index 5e46db4..d47f2d1 100644 --- a/tasks/source/tarball.yml +++ b/tasks/source/tarball.yml @@ -6,7 +6,7 @@ - name: build | tarball | download get_url: - url="{{ wkhtmltopdf_download_url }}" + url="{{ wkhtmltopdf_tarball_download_url }}" dest="{{ ansible_env.HOME }}/{{ wkhtmltopdf_tarball }}" owner="{{ wkhtmltopdf_user }}" group="{{ wkhtmltopdf_user }}" diff --git a/tasks/source/validation.yml b/tasks/source/validation.yml new file mode 100644 index 0000000..c1683a6 --- /dev/null +++ b/tasks/source/validation.yml @@ -0,0 +1,24 @@ +--- +# file: wkhtmltopdf/tasks/build/validation.yml +# +# validation tasks. +# + +- name: build | ensure build mandatory variables are set + fail: + msg="{{ item }} is a mandatory variable" + when: "{{ item }} is not defined" + with_items: + - wkhtmltopdf_architecture + - wkhtmltopdf_build + - wkhtmltopdf_build_args + - wkhtmltopdf_chroot_args + - wkhtmltopdf_dir_chroot + - wkhtmltopdf_dir_install + - wkhtmltopdf_dir_source + - wkhtmltopdf_dir_source_version + - wkhtmltopdf_force_build + - wkhtmltopdf_source_dependencies + - wkhtmltopdf_slug + - wkhtmltopdf_tarball + - wkhtmltopdf_tarball_download_url diff --git a/vars/package.yml b/vars/package.yml deleted file mode 100644 index 78240f8..0000000 --- a/vars/package.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -# file: wkhtmltopdf/vars/package.yml -# -# default values for variable specific to the package installation. -# - -wkhtmltopdf_package: "wkhtmltox-{{ wkhtmltopdf_version }}_linux-{{ ansible_distribution_release }}-{{ (ansible_architecture == 'x86_64') | ternary('amd64', 'i386') }}.deb" -wkhtmltopdf_download_url: "http://download.gna.org/wkhtmltopdf/{{ wkhtmltopdf_mm_version }}/{{ wkhtmltopdf_version }}/{{ wkhtmltopdf_package }}" diff --git a/vars/source.yml b/vars/source.yml deleted file mode 100644 index c6e7d5c..0000000 --- a/vars/source.yml +++ /dev/null @@ -1,27 +0,0 @@ ---- -# file: wkhtmltopdf/vars/source.yml -# -# default values for variable specific to the source installation. -# - -wkhtmltopdf_architecture: amd64 - -wkhtmltopdf_build_args: "linux-generic-{{ wkhtmltopdf_architecture }}" -wkhtmltopdf_build_dependencies: - - build-essential - - libssl-dev - - openssl - - xorg - -wkhtmltopdf_chroot_args: setup-schroot-generic - -wkhtmltopdf_dir_chroot: /var/chroot -wkhtmltopdf_dir_source: "{{ ansible_env.HOME }}" -wkhtmltopdf_dir_source_version: "{{ wkhtmltopdf_dir_source }}/wkhtmltox-{{ wkhtmltopdf_version }}" - -wkhtmltopdf_force_build: no - -wkhtmltopdf_slug: wkhtmltopdf/wkhtmltopdf - -wkhtmltopdf_tarball: "wkhtmltox-{{ wkhtmltopdf_version }}.tar.bz2" -wkhtmltopdf_download_url: "http://download.gna.org/wkhtmltopdf/{{ wkhtmltopdf_mm_version }}/{{ wkhtmltopdf_version }}/{{ wkhtmltopdf_tarball }}"