Let us take a closer look at the a2ensite ansible and how to use it for the Apache site with the support of our Server Management Support services at Bobcares.
a2ensite and Ansible
It is a script that configures apache2 to enable the provided site (which has a VirtualHost> block). It accomplishes this by generating symlinks in /etc/apache2/sites-enabled.
syntax :
name: Enable new site
shell: /usr/sbin/a2ensite {{ http_conf }}
notify: Reload Apache
Run the sudoa2ensite example.com
command to activate the virtual host within Apache.
The first method is safer because it gives Apache control over the process. The command
module is used again for this.
As we discovered above, the usage of a2ensite ansible is fairly simple:
- name: a2ensite {{ domain }}
command: a2ensite
{{ domain }}
notify:
- restart apache2
Ansible is a well-known open-source IT automation platform for scripting applications across multiple domains.
Using the ansible.builtin.template module, we must configure apache for the specific virtual host. And we need to enable a new site using the ansible.builtin.command module.
Enable the Apache site using Ansible and a2ensite
It’s worth noting that we can execute a playbook from a python anycodings ansible-runner script. In this scenario, we’re going to use the code below.
The following command is completely functional:
ansible -i path/to/inventory.yml host_name -m command -a"a2ensite site_name"
a2ensite example
We can go through the example given below to get a better idea of the a2ensite ansible process:
a2ensite /etc/apache2/sites-available/new-domain.conf
a2dissite /etc/apache2/sites-available/new-domain.conf
The Example for ‘enable apache2 site’ is given below for reference.
a2ensite example.com
We can type in the following code to enable the apache to enable the site:
#apache enable site:
sudo a2ensite domain1.com
Below given is an example of the ensite after the process:
a2ensite /etc/apache2/sites-available/new-domain.conf
a2dissite /etc/apache2/sites-available/new-domain.conf
[Need assistance with similar queries? We are here to help]
Conclusion
To conclude we have now learned more about a2ensite ansible and how to enable the Apache site using Ansible with the assistance of a2ensite with our Server management support services at Bobcares.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments