Ansible httpd php task

@francilio yes I do have that file there! fixed it. by using
/home/thor/playbooks/templates/phpinfo.php.j2
instead of
~/playbooks/templates/phpinfo.php.j2

all good worked as expected.

Hello, nashwan
You are correct. We have to provide the absolute path.

1 Like

The play book worked fine but the tak marked fail.
Bellow the script. Please advise :

  • name: “Ansible Setup Httpd and PHP”
    hosts: stapp03
    become: true
    become_user: root
    gather_facts: true
    tasks:
    • name: “Install apache”
      package: name=httpd state=present

    • name: “Install apache2-php5”
      package: name=php state=present

    • name: change document root
      replace:
      path: /etc/httpd/conf/httpd.conf
      regexp: “/var/www/html”
      replace: “/var/www/html/myroot”

    • name: “make root dir”
      file:
      path: /var/www/html/myroot
      state: directory
      mode: ‘0755’
      group: apache
      owner: apache

    • name: “template copying”
      copy:
      src: “~/playbooks/templates/phpinfo.php.j2”
      dest: “/var/www/html/myroot/phpinfo.php”
      group: apache
      mode: ‘0755’
      owner: apache

    • name: “Start Apache service”
      service:
      name: httpd
      state: restarted

    • name: “apache enable”
      service:
      name: httpd
      enabled: yes

Hello, chawki
What’s the failed message? Your replace module not looks fine. have you cross checked? It is replaced?

Here is your mistake: you should add DocumentRoot at the beginning of each regexp and replace
regexp: “DocumentRoot /var/www/html”

Just need to write the playbook according to question. Working solution: Ansible httpd and php kodekloud