software:service:ansible
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| software:service:ansible [2022/09/26 08:27] – warnaud | software:service:ansible [2022/09/28 13:34] (current) – [Examples] warnaud | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== Ansible ====== | ||
| + | ====== Definitions ====== | ||
| + | ===== Control node ===== | ||
| + | Main node where Ansible is installed and will have access via ssh to managed node\\ | ||
| + | Very sensible machine (access to everything) <=> reinforced security | ||
| + | ===== Managed node ===== | ||
| + | All nodes managed by Ansible. They have a user with privilege elevation and ssh connection ready for control node | ||
| + | ===== Inventory ===== | ||
| + | Inventory of the machines in ini (flat) or yaml and variable files host_vars and group_vars folders it can be static or dynamic (python), it can uses patterns | ||
| + | ===== Groups ===== | ||
| + | We can regroup machines into groups (example nginx/ | ||
| + | ==== Group_vars ==== | ||
| + | all varaibles for the same group | ||
| + | ==== Host_vars ==== | ||
| + | in opposition to group_vars, host_vars contains variable(s) to specific host. Has precedence on group_vars where the machine is included | ||
| + | ===== Task ===== | ||
| + | one action (create user/use template/ | ||
| + | ===== Module ===== | ||
| + | define action to a specific action (postgresql: | ||
| + | ===== Roles ===== | ||
| + | it's a group of actions specific to a deployment (install nginx/ | ||
| + | Has different tools to help: tasks, templates, handlers, variables, meta\\ | ||
| + | Tons available on the galaxy hub\\ | ||
| + | :!: use git/ | ||
| + | ===== Playbook ===== | ||
| + | File that coordinate inventory/ | ||
| + | ===== Plugin ===== | ||
| + | Improves Ansible ( tests/ | ||
| + | |||
| + | ====== Install ====== | ||
| + | ===== Control node ===== | ||
| + | <code bash> apt install ansible</ | ||
| + | <code bash> yum install ansible || dnf install ansible</ | ||
| + | ===== Managed node ===== | ||
| + | Python is required | ||
| + | <code bash> apt install python</ | ||
| + | <code bash> yum install python || dnf install python</ | ||
| + | |||
| + | ====== SSH ====== | ||
| + | ===== Generate ===== | ||
| + | <code bash> ssh-keygen -t ecdsa</ | ||
| + | ===== Install ===== | ||
| + | <code bash> ssh-copy-id -i ~/ | ||
| + | ===== more security ===== | ||
| + | Add in .ssh/ | ||
| + | <code perl> from=" | ||
| + | Other values: | ||
| + | <code perl> | ||
| + | ===== .ssh/config ===== | ||
| + | <code perl> | ||
| + | Host * | ||
| + | User ansible | ||
| + | IdentityFile / | ||
| + | Compression yes | ||
| + | ForwardAgent yes</ | ||
| + | ServerAliveInterval 300 | ||
| + | TCPKeepAlive no | ||
| + | ServerAliveCountMax 2 | ||
| + | IPQoS=throughput | ||
| + | ====== Managed node user ====== | ||
| + | ===== Create user ===== | ||
| + | <code bash> | ||
| + | ===== Grant sudo ===== | ||
| + | <code bash> | ||
| + | visudo | ||
| + | usermod -aG sudo ansible</ | ||
| + | We add user **ansible** to **sudo** OR **wheel** group | ||
| + | ==== test ==== | ||
| + | <code bash> | ||
| + | sudo -l # for a list | ||
| + | </ | ||
| + | ===== SSHkey ===== | ||
| + | <code bash> ssh localhost # to create ~/.ssh folder </ | ||
| + | <code bash> | ||
| + | ===== Check ansible connection from control node ===== | ||
| + | **from control node**< | ||
| + | <code bash> ansible -i " | ||
| + | ===== Examples ===== | ||
| + | <code bash> ansible -i " | ||
| + | Gather fact from machine | ||
| + | <code bash> ansible -i " | ||
| + | ====== References ====== | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | |||
