How to install apache2 using salt stack

To install Apache2 using SaltStack, you can follow these steps:

  1. Create a new file called apache.sls in the /srv/salt/ directory:
sudo mkdir -p /srv/salt/
sudo nano /srv/salt/apache.sls

2. Add the following code to the apache.sls file:

apache:
  pkg.installed:
    - name: httpd

apache_service:
  service.running:
    - name: httpd
    - enable: True

This code defines two SaltStack states: apache and apache_service. The apache state installs the Apache2 package using the httpd name, while the apache_service state ensures that the httpd service is running and enabled.

3. Apply the state to the target minions:

sudo salt '*' state.apply apache

This command applies the apache state to all minions that are configured to connect to the SaltStack master.

4. Verify that Apache2 is installed and running:

sudo salt '*' cmd.run 'systemctl status httpd'

This command checks the status of the httpd service on all minions. If Apache2 is installed and running, you should see output similar to the following:

httpd.service - The Apache HTTP Server
  Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Active: active (running) since Mon 2021-10-18 14:29:48 UTC; 2 days ago

That’s it! You have successfully used SaltStack to install and configure Apache2 on your target minions. You can use this same approach to automate the installation and configuration of other software packages and services on your infrastructure.

Leave a Reply

Your email address will not be published. Required fields are marked *