This Ansible playbook automates the deployment and configuration of a Go web server on remote servers. It performs tasks such as creating directories, copying files, and configuring services to set up a functional Go web application.
- Ansible installed on the control machine.
- Access to remote servers via SSH.
- Proper SSH credentials (e.g., private key) for connecting to remote servers.
-
Clone this repository:
git clone https://github.com/your-username/your-repo.git cd your-repo
-
Update the Ansible inventory (hosts file) with your server details:
[web_servers] server1 ansible_user=your-ssh-user ansible_ssh_private_key_file=your-ssh-key.pem
-
Modify playbook variables and configurations (if needed) in playbook.yaml.
-
Run the Ansible playbook:
ansible-playbook -i hosts playbook.yaml
- Create Destination Directory: Ensure the existence of the
/home/app-ansible directory
. - Remove Existing goapp File: Delete any existing goapp file in
/home/app-ansible
. - Copy New Binary File: Copy the latest binary file to
/home/app-ansible/goapp
. - Copy Nginx Configuration: Place the go.conf Nginx configuration file in
/etc/nginx/conf.d/
. - Reload systemd (daemon-reload): Execute
systemctl daemon-reload
to reload systemd configurations. - Reload Nginx: Restart the Nginx service to apply the new configuration.
- Configure systemd Service: Use a template to configure the goapp systemd service.
- Restart goapp Service: Restart the goapp service using sudo service goapp restart.
- This playbook assumes the target servers are running systemd and Nginx.
- Customize the playbook according to your specific environment and requirements.