422 Role vbotka.freebsd.apache PHP
Use case
Use the role vbotka.freebsd.apache to configure PHP in Apache HTTP Server. Use iocage property
host_hostname to create a jail.
Tree
shell> tree .
.
├── ansible.cfg
├── hosts
├── host_vars
│ ├── iocage_04
│ │ └── ansible-client-apache.yml
│ └── www-4
│ └── apache.yml
├── iocage.ini
└── pb-apache.yml
Synopsis
The playbook vbotka.freebsd.pb_iocage_ansible_clients.yml creates and starts one jail.
The playbook
pb-apache.ymlconfigures PHP in the Apache HTTP Server in the jail.
Requirements
Template
ansible_client_apachecreated in 209 Create iocage pkglist file
Notes
iocageoption--nameprovides “NAME instead of a UUID for the new jail”.iocagepropertyhost_hostnameprovides “The hostname of the jail. Default: UUID”.Make sure DHCP and dynamic DNS are configured so that
host_hostnameand--nameresolve.
ansible.cfg
[defaults]
gathering = explicit
callback_result_format = yaml
display_skipped_hosts = false
host_key_checking = false
[connection]
pipelining = true
Inventory iocage.ini
iocage_04 ansible_host=10.1.0.29
[iocage]
iocage_04
[iocage:vars]
ansible_user=admin
ansible_become=true
ansible_python_interpreter=auto_silent
host_vars
host_vars/iocage_04/ansible-client-apache.yml
properties:
notes: "vmm={{ inventory_hostname }}"
bpf: 1
dhcp: 1
vnet: 1
clones_host_hostname:
www-4:
template: ansible_client_apache
host_vars/www-4/apache.yml
apache_install: false
apache_confd: false
apache_servername: www-4
apache_serveradmin: admin@www-4
apache_httpd_conf_modules:
- {module: php_module, mod: libphp.so}
apache_directory_blocks:
- Directory: /usr/local/www/apache24/data/
Includefile: usr-local-www-apache-data.conf
Conf:
- "DirectoryIndex index.php index.html index.htm"
- "AddType application/x-httpd-php .php"
- "AddType application/x-httpd-php-source .phps"
- "Options Indexes FollowSymLinks"
- "AllowOverride All"
- "Require all granted"
Create and start jails
(env) > ansible-playbook vbotka.freebsd.pb_iocage_ansible_clients.yml \
-i iocage.ini \
-t clone_host_hostname -e clone_host_hostname=true
PLAY [Create and start jails. Optionally stop and destroy jails.] **************
TASK [Get pool.] ***************************************************************
ok: [iocage_04]
TASK [Create clones host_hostname] *********************************************
changed: [iocage_04] => (item=www-4 ansible_client_apache)
TASK [Start clones host_hostname] **********************************************
changed: [iocage_04]
PLAY RECAP *********************************************************************
iocage_04 : ok=3 changed=2 unreachable=0 failed=0 skipped=8 rescued=0 ignored=0
Inventory hosts
hosts
www-4
[www]
www-4
[www:vars]
ansible_user=admin
ansible_become=true
ansible_python_interpreter=auto_silent
Playbook pb-apache.yml
- name: Create Apache HTTP Server.
hosts: www
gather_facts: true
roles:
- vbotka.freebsd.apache
Playbook output - Create server
(env) > ansible-playbook pb-apache.yml -i hosts
PLAY [Create Apache HTTP Server.] **********************************************
TASK [Gathering Facts] *********************************************************
[ERROR]: Task failed: Failed to connect to the host via ssh: ssh: Could not resolve hostname www-4: Temporary failure in name resolution
Task failed.
<<< caused by >>>
Failed to connect to the host via ssh: ssh: Could not resolve hostname www-4: Temporary failure in name resolution
fatal: [www-4]: UNREACHABLE! =>
changed: false
msg: 'Task failed: Failed to connect to the host via ssh: ssh: Could not resolve hostname
www-4: Temporary failure in name resolution'
unreachable: true
PLAY RECAP *********************************************************************
www-4 : ok=0 changed=0 unreachable=1 failed=0 skipped=0 rescued=0 ignored=0
Create info.php
(env) > ssh admin@www-4 cat /usr/local/www/apache24/data/info.php
<?php
phpinfo();
?>
Results
Test the configuration
(env) > ssh admin@www-4 sudo service apache24 configtest Performing sanity check on apache24 configuration: Syntax OK
In a browser, open the page
http://www-4/info.php. The content should be similar to this one