• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Create Ansible Playbook to Install Apache Server

  • 01:02 vim hosts
  • 04:17 vim httpd.yml
  • 04:37 ansible-playbook httpd.yml
{{postValue.id}}

To Create Ansible Playbook to Install Apache Server

Apache is a web server that is used on the Internet. It is easy to set up and configure on Linux distributions including Ubuntu and Debian, as it comes in the package repositories and includes a default configuration that works out of the box. This video will cover the installation of an apache server using Ansible.

Installation process:

Create a playbook to isntall apache server on your host machine

[root@localhost ansible]# vim httpd.yml 

snap1

After creating playbook now let’s run this using the following command

[root@localhost ansible]# ansible-playbook httpd.yml 
PLAY [httpd is there] *********************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************
ok: [192.168.6.111]
TASK [ensure httpd is installed] **********************************************************************************************
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop 
to supply multiple items and specifying `pkg: "{{item}}"`, please use `pkg: ['nano', 'httpd']` and remove the loop. This 
feature will be removed from ansible-base in version 2.11. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
changed: [192.168.6.111] => (item=['nano', 'httpd'])

PLAY RECAP ********************************************************************************************************************
192.168.6.111              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   
Now I am going to uninstall the httpd from our host machine using the following playbook
[root@localhost ansible]# vim httpd.yml

snap2

And now run this playbook to uninstall the apache from the host machine.

[root@localhost ansible]# ansible-playbook httpd.yml 
PLAY [httpd is there] *********************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************
ok: [192.168.6.111]
TASK [ensure httpd is installed] **********************************************************************************************
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop 
to supply multiple items and specifying `pkg: "{{item}}"`, please use `pkg: ['nano', 'httpd']` and remove the loop. This 
feature will be removed from ansible-base in version 2.11. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
changed: [192.168.6.111] => (item=['nano', 'httpd'])

PLAY RECAP ********************************************************************************************************************
192.168.6.111              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

Now in case if you want to install multiple application packages on your host machine using ansible

snap3

Now run this playbook to install apache and nano to install on your host machine

[root@localhost ansible]# ansible-playbook httpd.yml%%

PLAY [httpd is there] *********************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************
ok: [192.168.6.111]
TASK [ensure httpd is installed] **********************************************************************************************
[DEPRECATION WARNING]: Invoking "yum" only once while using a loop via squash_actions is deprecated. Instead of using a loop 
to supply multiple items and specifying `pkg: "{{item}}"`, please use `pkg: ['nano', 'httpd']` and remove the loop. This 
feature will be removed from ansible-base in version 2.11. Deprecation warnings can be disabled by setting 
deprecation_warnings=False in ansible.cfg.
changed: [192.168.6.111] => (item=['nano', 'httpd'])

PLAY RECAP ********************************************************************************************************************
192.168.6.111              : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

With this method installation of apache on ansible host machine comes to an end.

Tags:
ethan
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is inventory file in ansible?

A

The Ansible inventory file defines the hosts and groups of hosts upon which commands, modules, and tasks in a playbook operate.

Q

How to install multiple application in host machine using ansible?

A

To install multiple application you have to use loop insid the playbook.

Q

How to unistall any application in host machine using ansible

A

you can use status=absent in ansible playbook to uninstall apny application.

Q

How do I see a list of all of the ansible_ variables?

A

To see a list of all of the facts that are available about a machine, you can run the setup module as an ad-hoc action:
ansible -m setup hostname

Q

How do I see all the variables specific to my host?

A

Using this command

ansible -m debug -a "var=hostvars['hostname']" localhost

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Luk Van De Looverbosch ?
How to create a root ?

Hello,
How to create root@linuxhelp in Linux Mint 20.1 64-bit ?
Thanks in advance for your reply.
Best regards.

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.