Ansible Setup Httpd and PHP Kodekloud

 


Solution:

In [email protected]_host 

cd ~/playbooks

vi httpd.yml

- name: Setup Httpd and PHP
hosts: stapp03
become: yes
tasks:
- name: Install latest version of httpd and php
package:
name:
- httpd
- php
state: latest
- name: Replace default DocumentRoot in httpd.conf
replace:
path: /etc/httpd/conf/httpd.conf
regexp: DocumentRoot \"\/var\/www\/html\"
replace: DocumentRoot "/var/www/html/myroot"
- name: Create the new DocumentRoot directory if it does not exist
file:
path: /var/www/html/myroot
state: directory
owner: apache
group: apache
- name: Use Jinja2 template to generate phpinfo.php
template:
src: /home/thor/playbooks/templates/phpinfo.php.j2
dest: /var/www/html/myroot/phpinfo.php
owner: apache
group: apache
- name: Start and enable service httpd
service:
name: httpd
state: started
enabled: yes

 Here the server is stapp03 but it will be dependent on question

Now run this ansible command

ansible-playbook  -i inventory httpd.yml

To check we can go to the server

ssh [email protected]

rpm -qa | grep httpd

rpm -qa | grep php



Share on Google Plus

About Ashadullah Shawon

I am Ashadullah Shawon. I am a Software Engineer. I studied Computer Science and Engineering (CSE) at RUET. I Like To Share Knowledge. Learn More: Click Here
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment