This section explains how to leverage this VM for automating configuration management, application deployment, and task automation using Ansible and Semaphore UI.
In Ansible automation, you can use a wide variety of machines as target hosts. Since Ansible is agentless, it communicates over standard protocols like SSH (for Linux/Unix-based systems) and WinRM (for Windows-based systems).
The VM comes with the AnsibleExampleProject to get you started with. To run the example ‘install_apache.yaml’ playbook on localhost follow below steps.
Connect to Ansible Semaphore VM using terminal and run ‘apache2’ command, it will return with error ‘Command apache2 not found’.
apache2
cat /home/ubuntu/.ssh/id_rsa
To delete the existing keys run:
sudo rm -r /home/ubuntu/.ssh/id_rsa /home/ubuntu/.ssh/id_rsa.pub
To create the new SSH key pair run below command and keep the passphrase empty.
ssh-keygen -t rsa -b 4096 -f /home/ubuntu/.ssh/id_rsa
Now copy the newly created ssh private key from begining to end by running:
cat /home/ubuntu/.ssh/id_rsa
Here AnsibleExampleProject is already created and configured for you to get started.
Go to Key Store option from left pane. Click on edit option in front of “Ansible Example KS” . New pop up will appear. Tick the Override checkbox at the bottom left. This will enable the page to edit. Paste the id_rsa private key content from the ssh terminal as shown in the above command. Keep all other fields as it is. Save the changes.
sudo apt remove apache2 -y && sudo apt autoremove -y
Follow below steps to run Ansible Example Template on any other ubuntu host. Please note that install_apache.yaml playbook is written with apt package manager. So it will run successfully on host which uses apt package manager like ubuntu and debian.
First we need to copy the public keys from Ansible VM to the target ubuntu VM. To do so connect to Ansible VM terminal and run below command:
Copy the keys on target VM using ssh-copy-id command:
ssh-copy-id user@target-host-ip
e.g ssh-copy-id ubuntu@172.190.241.204
It will prompt - ‘Are you sure you want to continue connecting (yes/no/[fingerprint])?’, enter yes here.
It will ask for the password of target machine. Provide the password and hit enter.
It should show ‘Number of key(s) added: 1’ success message.
ssh user@target-host-ip
e.g ssh ubuntu@172.190.241.204
It will not ask you for any password and connect you to the target machine using SSH keys.
apache2
Now we are good to go for playbook execution on target machine.
Run the template and it should install apache2 on both localhost and new ubuntu target machine.
For more details on Ansible or Semaphore please refer to Official Documentation Page