Difference between revisions of "Ansible Setup"
Line 1: | Line 1: | ||
<html> | |||
<style> | |||
.optional{ background: yellow;} | |||
</style> | |||
<div class="optional"> | |||
* Download and install Miniconda: | * Download and install Miniconda: | ||
curl -OL https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh | curl -OL https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh | ||
Line 18: | Line 23: | ||
python --version | python --version | ||
</div> | |||
</html> | |||
'''Ubuntu 18.04''' | '''Ubuntu 18.04''' | ||
Line 25: | Line 32: | ||
sudo apt-add-repository --yes --update ppa:ansible/ansible | sudo apt-add-repository --yes --update ppa:ansible/ansible | ||
sudo apt install ansible | sudo apt install ansible | ||
ansible-galaxy collection install community.general | |||
*Verify that Ansible is installed: | *Verify that Ansible is installed: |
Revision as of 15:06, 24 June 2022
Ubuntu 18.04
sudo apt update sudo apt install software-properties-common sudo apt-add-repository --yes --update ppa:ansible/ansible sudo apt install ansible ansible-galaxy collection install community.general
- Verify that Ansible is installed:
ansible --version
Configure Ansible
By default, Ansible’s configuration file location is /etc/ansible/ansible.cfg.
In most cases, the default configurations are enough to get you started using Ansible. In this example, you will use Ansible’s default configurations.
- To view a list of all current configs available to your control node, use the
ansible-config
command line utility.
ansible-config list
Create an Ansible Inventory
Ansible keeps track of its managed nodes using an inventory file located in /etc/ansible/hosts.
In the inventory file, you can group your managed nodes and use these groups to target specific hosts that make up your infrastructure
- Add your nodes to the default inventory file.
File: /etc/ansible/hosts
[nginx] 203.0.113.0 [wordpress] 203.0.113.1
Each bracketed label denotes an Ansible group . Grouping your nodes by function will make it easier to run commands against the correct set of nodes.
Note
The /etc/ansible directory will not exist by default in some environments. If you find that this is the case, create it manually with the following command:
mkdir /etc/ansible/
If you are using a non-standard SSH port on your nodes, include the port after a colon on the same line within your hosts file (203.0.113.1:2222).
Test connection to server
ansible all -u root -m ping --private-key ~/.ssh/ansible
Create a playbook
nano server.yml
--- --- - hosts: webserver tasks: - name: install apache package: name: apache2 state: latest - hosts: fileserver tasks: - name: install nginx package: name: nginx state: latest