0

Using the playbook below I am finding the /etc/apache2/envvars are not getting set properly. I found references that Apache 2.4 is to be started via the apache2ctl module and tried using it to start the service. After an EC2 instance is launched I find the Apache2.4 service not running due to errors. Everything is being done by this playbook:

--- # Build Web Server
- name: Install Apache
hosts: localhost
become: yes
connection: local
gather_facts: yes
tasks:

- name: Add Repository for PHP 5.6
  apt_repository:
    repo: ppa:ondrej/php
    state: present

- name: Install Web Server Package
  apt:
    pkg: "{{ item }}"
    state: present
    update_cache: yes
  with_items:
  - "apache2"
  - "php5.6"
  - "php5.6-mbstring"
  - "php5.6-mcrypt"
  - "php5.6-mysql"
  - "php5.6-xml"
  - "php5.6-cli"
  - "libapache2-mod-php5.6"

- name: enable modules
  command: "a2enmod {{item}}"
  with_items:
  - rewrite
  - ssl


- name: Update Apache Config
  copy:
    src: /data/000-default.conf
    dest: /etc/apache2/sites-available
    owner: root
    group: root
    mode: 0644

- name: Enable Default website
  command: "a2ensite 000-default.conf"

- name: Update PHP CLI php.ini
  lineinfile:
    dest: /etc/php/5.6/cli/php.ini
    state: present
    insertbefore: EOF
    regexp: '^error_reporting'
    line: 'error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED'

  notify:
    - StartHttpd
  tags:
  - installapache
  handlers:
  - name: StartHttpd
    command: "apache2ctl restart"

After running the above playbook ...

ubuntu@ip-10-250-0-62:~$ sudo apache2 -S
[Thu Jun 01 20:53:02.524073 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOCK_DIR} is not defined
[Thu Jun 01 20:53:02.524158 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_PID_FILE} is not defined
[Thu Jun 01 20:53:02.524231 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_RUN_USER} is not defined
[Thu Jun 01 20:53:02.524272 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_RUN_GROUP} is not defined
[Thu Jun 01 20:53:02.524311 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:02.532379 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_RUN_DIR} is not defined
[Thu Jun 01 20:53:02.532637 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:02.532830 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:02.532886 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}

ubuntu@ip-10-250-0-62:~$ sudo apache2ctl restart

ubuntu@ip-10-250-0-62:~$ sudo apache2 -S
[Thu Jun 01 20:53:14.440314 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOCK_DIR} is not defined
[Thu Jun 01 20:53:14.440398 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_PID_FILE} is not defined
[Thu Jun 01 20:53:14.440476 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_RUN_USER} is not defined
[Thu Jun 01 20:53:14.440519 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_RUN_GROUP} is not defined
[Thu Jun 01 20:53:14.440568 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:14.448516 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_RUN_DIR} is not defined
[Thu Jun 01 20:53:14.448807 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:14.448979 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:14.449035 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}

ubuntu@ip-10-250-0-62:~$ sudo su -

root@ip-10-250-0-62:~# . /etc/apache2/envvars

root@ip-10-250-0-62:/root# apache2ctl restart

root@ip-10-250-0-62:/root# apache2 -S
VirtualHost configuration: *:80 ip-10-250-0-62.us-west-2.compute.internal (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

1 Answer 1

0

Use service: name=apache (name might vary among distributions). apache2ctl is complaining that environment variables are not set. Those parameters are likely to be set during startup with the init manager (which is called with the service module).

1
  • Henrik Pingel Thank you. I found the issue is that Ansible is issuing a service apache2 restart which is the cause of the problem. The solution in this case is to use the command feature to issue a /usr/sbin/apache2ctl restart command. The issue is within the distribution / package. Since doing so I have not experienced any further problems. Apparently in Ubuntu 16.04 Apache 2.4 is offering more than one path to command the service as found in /usr/sbin/apache* Jun 6, 2017 at 1:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .