diff --git a/tasks/install_libzip.yaml b/tasks/install_libzip.yaml new file mode 100644 index 0000000..ed4199d --- /dev/null +++ b/tasks/install_libzip.yaml @@ -0,0 +1,42 @@ +--- +- name: Verify that libzip is installed + stat: + path: /usr/local/libzip + register: libzip_install_stat + +- name: Download libzip package + get_url: + url: "{{ php_libzip_download_url }}" + dest: "{{ role_path }}/files/" + timeout: 120 + become: false + run_once: true + delegate_to: localhost + register: _php_libzip_package + when: + - not libzip_install_stat.stat.exists + +- name: Unarchive libzip + unarchive: + src: "files/{{ php_libzip_download_url | basename }}" + dest: /usr/local/src + creates: /usr/local/src/libzip-{{ php_libzip_version }} + remote_src: false + register: libzip_unarchive + when: + - not libzip_install_stat.stat.exists + - _php_libzip_package is not skipped + +- name: Install libzip + shell: "{{ item }}" + args: + chdir: /usr/local/src/libzip-{{ php_libzip_version }} + loop: + - ./configure --prefix=/usr/local/libzip + - make + - make install + when: + - libzip_unarchive is changed + - php_libzip_version is version("1.4.0", operator="<") + tags: + - skip_ansible_lint diff --git a/tasks/main.yml b/tasks/main.yml index f61fb0a..9a5f3be 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,203 +1,156 @@ --- -- block: - - import_tasks: prepare.yaml - - - name: Install dependencies - yum: - name: "{{ php_dependencies }}" - state: installed - async: 1000 - poll: 0 - changed_when: False - register: yum_sleeper - - - name: Wait for dependencies install complete - async_status: - jid: "{{ yum_sleeper.ansible_job_id }}" - register: yum_sleeper_job_result - until: yum_sleeper_job_result.finished - retries: 300 - when: - - yum_sleeper is not skipped - - - name: Ensure {{ php_web_user }} group exists - group: - name: "{{ php_web_user }}" - system: yes - state: present - tags: - - user - - - name: Ensure {{ php_web_user }} user exists - user: - name: "{{ php_web_user }}" - shell: /sbin/nologin - home: /var/cache/nginx - group: "{{ php_web_user }}" - system: yes - move_home: yes - state: present - tags: - - user - - - name: Verify that libzip is installed - stat: - path: /usr/local/libzip - register: libzip_install_stat - - - name: Download libzip package - get_url: - url: "{{ php_libzip_download_url }}" - dest: "{{ role_path }}/files/" - timeout: 120 - async: 120 - poll: 5 - become: false - run_once: true - delegate_to: localhost - register: _php_libzip_package - when: - - not libzip_install_stat.stat.exists - - - name: Unarchive libzip - unarchive: - src: "files/{{ php_libzip_download_url | basename }}" - dest: /usr/local/src - creates: /usr/local/src/libzip-{{ php_libzip_version }} - remote_src: false - register: libzip_unarchive - when: - - not libzip_install_stat.stat.exists and _php_libzip_package is not skipped - - - name: Install libzip - shell: "{{ item }}" - args: - chdir: /usr/local/src/libzip-{{ php_libzip_version }} - loop: - - ./configure --prefix=/usr/local/libzip - - make - - make install - when: - - libzip_unarchive is changed - tags: - - skip_ansible_lint - - - name: Download php package - get_url: - url: "{{ php_download_url }}" - dest: "{{ role_path }}/files/" - timeout: 120 - async: 120 - poll: 5 - become: false - run_once: true - delegate_to: localhost - when: - - not php_installed_stat.stat.exists - register: _php_package - - - name: Unarchive php-{{ php_version }} - unarchive: - src: "files/{{ php_download_url | basename }}" - dest: /usr/local/src/ - creates: /usr/local/src/php-{{ php_version }} - remote_src: false - register: php_unarchive - when: - - _php_package is not skipped and not php_installed_stat.stat.exists - - - name: Compile and Install - shell: "{{ php_build_parameters }}" - args: - chdir: /usr/local/src/php-{{ php_version }} - async: 1800 - poll: 0 - register: php_install_status - changed_when: False - when: - - php_force_install|bool or not php_installed_stat.stat.exists - - php_unarchive is changed - tags: - - skip_ansible_lint - - - name: Wait for complie/install complete - async_status: - jid: "{{ php_install_status.ansible_job_id }}" - register: php_install_poll_status - until: php_install_poll_status.finished - retries: 600 - when: - - php_install_status is not skipped - - - name: Ensure log && configuration directory - file: - path: "{{ item }}" - state: directory - owner: "{{ php_web_user }}" - group: "{{ php_web_user }}" - mode: "755" - loop: - - "{{ php_log_path }}" - - "{{ php_fpm_pid | dirname }}" - - "/usr/local/php-{{ php_version }}/etc/php.d" - - "/usr/local/php-{{ php_version }}/etc/php-fpm.d" - - - name: Copy php-fpm configuration files - template: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - loop: - - src: php.ini.j2 - dest: /usr/local/php-{{ php_version }}/etc/php.ini - - src: php-fpm.conf.j2 - dest: /usr/local/php-{{ php_version }}/etc/php-fpm.conf - - src: www.conf.j2 - dest: /usr/local/php-{{ php_version }}/etc/php-fpm.d/www.conf - diff: true - notify: - - restart php-fpm - - - name: Ensure directory permissions - file: - path: /usr/local/php-{{ php_version }} - state: directory - owner: "{{ php_web_user }}" - group: "{{ php_web_user }}" - recurse: yes - - - name: Symlink - file: - src: /usr/local/php-{{ php_version }} - dest: /usr/local/php - state: link - force: yes - when: - - php_force_install|bool or not php_installed_stat.stat.exists - - - name: Startup for systemd - template: - src: php-fpm.service.j2 - dest: /usr/lib/systemd/system/php-fpm.service - diff: true - - - name: Ensure php-fpm.service started - systemd: - name: php-fpm.service - state: started - enabled: yes - daemon_reload: yes - - - import_tasks: post_task.yaml - rescue: - - name: Clean failed version - file: - path: /usr/local/php-{{ php_version }} - state: absent - always: - - name: Clean source packages - file: - path: "{{ item }}" - state: absent - loop: - - /usr/local/src/libzip-{{ php_libzip_version }} - - /usr/local/src/php-{{ php_version }} +- import_tasks: prepare.yaml + +- name: Install dependencies + yum: + name: "{{ php_dependencies }}" + state: installed + async: 1000 + poll: 0 + changed_when: False + register: yum_sleeper + +- name: Wait for dependencies install complete + async_status: + jid: "{{ yum_sleeper.ansible_job_id }}" + register: yum_sleeper_job_result + until: yum_sleeper_job_result.finished + retries: 300 + when: + - yum_sleeper is not skipped + +- name: Ensure {{ php_web_user }} group exists + group: + name: "{{ php_web_user }}" + system: yes + state: present + tags: + - user + +- name: Ensure {{ php_web_user }} user exists + user: + name: "{{ php_web_user }}" + shell: /sbin/nologin + home: /var/cache/nginx + group: "{{ php_web_user }}" + system: yes + move_home: yes + state: present + tags: + - user + +- name: Include install libzip task + include_tasks: install_libzip.yaml + +- name: Download php package + get_url: + url: "{{ php_download_url }}" + dest: "{{ role_path }}/files/" + timeout: 120 + become: false + run_once: true + delegate_to: localhost + when: + - ansible_local.php.version is not defined + register: _php_package + +- name: Unarchive php-{{ php_version }} + unarchive: + src: "files/{{ php_download_url | basename }}" + dest: /usr/local/src/ + creates: /usr/local/src/php-{{ php_version }} + remote_src: false + register: php_unarchive + when: + - _php_package is not skipped and ansible_local.php.version is not defined + +- name: Compile and Install + shell: "{{ php_build_parameters }}" + args: + chdir: /usr/local/src/php-{{ php_version }} + async: 1800 + poll: 0 + register: php_install_status + changed_when: False + when: + - php_force_install|bool or ansible_local.php.version is not defined + - php_unarchive is changed + tags: + - skip_ansible_lint + +- name: Wait for complie/install complete + async_status: + jid: "{{ php_install_status.ansible_job_id }}" + register: php_install_poll_status + until: php_install_poll_status.finished + retries: 600 + when: + - php_install_status is not skipped + +- name: Ensure log && configuration directory + file: + path: "{{ item }}" + state: directory + owner: "{{ php_web_user }}" + group: "{{ php_web_user }}" + mode: "755" + loop: + - "{{ php_log_path }}" + - "{{ php_fpm_pid | dirname }}" + - "/usr/local/php-{{ php_version }}/etc/php.d" + - "/usr/local/php-{{ php_version }}/etc/php-fpm.d" + +- name: Copy php-fpm configuration files + template: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + loop: + - src: php.ini.j2 + dest: /usr/local/php-{{ php_version }}/etc/php.ini + - src: php-fpm.conf.j2 + dest: /usr/local/php-{{ php_version }}/etc/php-fpm.conf + - src: www.conf.j2 + dest: /usr/local/php-{{ php_version }}/etc/php-fpm.d/www.conf + diff: true + notify: + - restart php-fpm + +- name: Ensure directory permissions + file: + path: /usr/local/php-{{ php_version }} + state: directory + owner: "{{ php_web_user }}" + group: "{{ php_web_user }}" + recurse: yes + +- name: Symlink + file: + src: /usr/local/php-{{ php_version }} + dest: /usr/local/php + state: link + force: yes + when: + - php_force_install|bool or ansible_local.php.version is not defined + +- name: Startup for systemd + template: + src: php-fpm.service.j2 + dest: /usr/lib/systemd/system/php-fpm.service + diff: true + +- name: Ensure php-fpm.service started + systemd: + name: php-fpm.service + state: started + enabled: yes + daemon_reload: yes + +- import_tasks: post_task.yaml + +- name: Clean source packages + file: + path: "{{ item }}" + state: absent + loop: + - /usr/local/src/libzip-{{ php_libzip_version }} + - /usr/local/src/php-{{ php_version }} diff --git a/tasks/prepare.yaml b/tasks/prepare.yaml index 475d1e3..32e6ffa 100644 --- a/tasks/prepare.yaml +++ b/tasks/prepare.yaml @@ -4,27 +4,10 @@ msg: "php_version must greater 7.0" when: php_version is version("7.0", operator="lt", strict=True) -- name: Verify that PHP is installed - stat: - path: /usr/local/php/bin/php - register: php_installed_stat - -- name: Get installed version - raw: /usr/local/php/bin/php --version | head -1 | awk '{print $2}' - register: get_php_installed_version - changed_when: false - when: - - php_installed_stat.stat.exists - tags: - - skip_ansible_lint - -- name: Set php_installed_version fact - set_fact: - php_installed_version: "{{ get_php_installed_version.stdout.strip() }}" - when: - - php_installed_stat.stat.exists - - get_php_installed_version is defined - - "'stdout' in get_php_installed_version" +- name: Verify libzip version + fail: + msg: "Libzip version greater than 1.4 is not currently supported" + when: php_libzip_version is version("1.4.0", operator=">=") - name: Remove installed same version file: @@ -32,16 +15,16 @@ state: absent when: - php_force_install|bool - - php_installed_version is defined - - php_installed_version is version(php_version, operator="eq", strict=True) + - ansible_local.php.version is defined + - ansible_local.php.version is version(php_version, operator="eq", strict=True) tags: - skip_ansible_lint - name: Message for PHP already installed fail: - msg: "expected version {{ php_version }} but {{ php_installed_version }} already installed. set php_force_install=true parameter to force reinstall" + msg: "expected version {{ php_version }} but {{ ansible_local.php.version }} already installed. set php_force_install=true parameter to force reinstall" when: - - php_installed_stat.stat.exists + # - php_installed_stat.stat.exists - not php_force_install - - php_installed_version is defined - - not php_installed_version is version(php_version, operator="eq", strict=True) + - ansible_local.php.version is defined + - not ansible_local.php.version is version(php_version, operator="eq", strict=True)