feat: first version of php role

This commit is contained in:
Lennard Brinkhaus 2022-12-19 19:39:12 +01:00
commit cfe978333b
Signed by: lennard.brinkhaus
GPG Key ID: 286421EC53998B22
11 changed files with 217 additions and 0 deletions

19
.editorconfig Normal file
View File

@ -0,0 +1,19 @@
# EditorConfig: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Defaults for all editor files
[*]
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
# Files with a smaller indent
[*.yml]
indent_size = 2
# Jinja2 template files
[*.j2]
end_of_line = lf

20
.gitignore vendored Normal file
View File

@ -0,0 +1,20 @@
local-configure.yml
.vagrant/
docs/_build/
roles/plone.plone_server
roles/jnv.unattended-upgrades
roles/tersmitten.fail2ban
roles/ANXS.hostname
roles/ANXS.apt
._*
bin/
lib/
include/
local/
tests.out
*.retry
*.log
vbox_host.cfg
.DS_Store
*.py[co]
.idea/

38
README.md Normal file
View File

@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

2
ansible.cfg Normal file
View File

@ -0,0 +1,2 @@
[defaults]
roles_path: ./../

5
defaults/main.yml Normal file
View File

@ -0,0 +1,5 @@
---
php_version_check: true
php_version: "8.1"
php_apt_key_url: "https://packages.sury.org/php/apt.gpg"
php_apt_repo: "deb https://packages.sury.org/php/ {{ ansible_distribution_release }} main"

34
meta/main.yml Normal file
View File

@ -0,0 +1,34 @@
galaxy_info:
author: Lennard Brinkhaus
description: Install and manage PHP
company: DragSE
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
platforms:
- name: Debian
versions:
- all
- name: Ubuntu
versions:
- all
galaxy_tags:
- php
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

36
tasks/install.yml Normal file
View File

@ -0,0 +1,36 @@
---
- block:
- name: Add PHP GPG Key
apt_key:
url: "{{ php_apt_key_url }}"
state: present
- name: Add PHP Repository
apt_repository:
repo: "{{ php_apt_repo }}"
state: present
- name: Update apt cache
apt:
cache_valid_time: 3600
update_cache: true
register: _pre_update_apt_cache
until: _pre_update_apt_cache is succeeded
when:
- ansible_pkg_mgr == "apt"
- name: Uninstall old Version Packages
package:
name: "{{ php_del_libs }}"
state: absent
- name: Install PHP Packages
package:
name: "{{ php_libs }}"
state: present
update_cache: true
register: _install_packages
until: _install_packages is succeeded
retries: 5
delay: 2
when: (not php_version_check|bool) or (php_active_version != php_version)

16
tasks/main.yml Normal file
View File

@ -0,0 +1,16 @@
---
- name: "Check PHP version"
ansible.builtin.shell: "php --version | cut -d' ' -f 2 | cut -d'.' -f 1-2 | head -1"
args:
executable: /bin/bash
register: php_active_version_sout
changed_when: false
failed_when: false
when: php_version_check|bool
- name: "Set active version"
set_fact:
php_active_version: "{{ php_active_version_sout.stdout }}"
when: php_version_check|bool
- include_tasks: install.yml

1
tests/inventory Normal file
View File

@ -0,0 +1 @@
192.168.1.142

5
tests/test.yml Normal file
View File

@ -0,0 +1,5 @@
---
- hosts: all
remote_user: root
roles:
- role-php

41
vars/main.yml Normal file
View File

@ -0,0 +1,41 @@
---
# vars file for role-php
php_libs:
- "libsodium23"
- "psmisc"
- "libpcre2-8-0"
- "php-common"
- "php-pear"
- "php{{ php_version }}-cli"
- "php{{ php_version }}-common"
- "php{{ php_version }}-opcache"
- "php{{ php_version }}-fpm"
- "php{{ php_version }}-curl"
- "php{{ php_version }}-gd"
- "php{{ php_version }}-mbstring"
- "php{{ php_version }}-mysql"
- "php{{ php_version }}-opcache"
- "php{{ php_version }}-readline"
- "php{{ php_version }}-xml"
- "php{{ php_version }}-zip"
- "php{{ php_version }}-bcmath"
- "php{{ php_version }}-intl"
php_del_libs:
- "psmisc"
- "php-common"
- "php-pear"
- "php{{ php_active_version }}-cli"
- "php{{ php_active_version }}-common"
- "php{{ php_active_version }}-opcache"
- "php{{ php_active_version }}-fpm"
- "php{{ php_active_version }}-curl"
- "php{{ php_active_version }}-gd"
- "php{{ php_active_version }}-mbstring"
- "php{{ php_active_version }}-mysql"
- "php{{ php_active_version }}-opcache"
- "php{{ php_active_version }}-readline"
- "php{{ php_active_version }}-xml"
- "php{{ php_active_version }}-zip"
- "php{{ php_active_version }}-bcmath"
- "php{{ php_active_version }}-intl"