Compare commits
9 Commits
d05a5d8c98
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
cb3be3acd9
|
|||
|
c3c44f0bf9
|
|||
|
37f9110b3a
|
|||
|
ed15164678
|
|||
|
0920465a89
|
|||
|
fccade82b0
|
|||
|
77754bd2ce
|
|||
|
2a40ae1970
|
|||
|
99b976d795
|
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
inventory/*.yml
|
||||||
|
!inventory/*.example.yml
|
||||||
90
README.md
90
README.md
@@ -1 +1,91 @@
|
|||||||
# Ansible
|
# Ansible
|
||||||
|
|
||||||
|
## Setup
|
||||||
|
|
||||||
|
Rename `inventory/inventory.example.yml` to `inventory/inventory.yml` and adjust the host IPs and usernames as needed.
|
||||||
|
|
||||||
|
To install and use Ansible on Windows, follow the [WSL Setup Instructions](#wsl-setup-instructions) below.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
run a playbook:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ansible-playbook playbooks/<playbook_name>.yml
|
||||||
|
```
|
||||||
|
|
||||||
|
run a playbook with sudo:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
ansible-playbook playbooks/<playbook_name>.yml -K
|
||||||
|
```
|
||||||
|
|
||||||
|
## WSL Setup Instructions
|
||||||
|
|
||||||
|
To use Ansible on Windows, you need to set up Windows Subsystem for Linux (WSL).
|
||||||
|
You then have the option to open a local Folder in VSCode and open a WSL terminal that points to the same folder under WSL.
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
To enable proper file permissions for Ansible on WSL, you need to configure the WSL automount settings.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo nano /etc/wsl.conf
|
||||||
|
```
|
||||||
|
|
||||||
|
Add the following lines:
|
||||||
|
|
||||||
|
```ini
|
||||||
|
[automount]
|
||||||
|
enabled = true
|
||||||
|
options = "metadata,umask=022,fmask=0111"
|
||||||
|
```
|
||||||
|
|
||||||
|
If you use a Network Drive, you have to mount it manually:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo mkdir /mnt/<drive_letter>
|
||||||
|
sudo mount -t drvfs <drive_letter>: /mnt/<drive_letter> -o metadata,umask=022,fmask=0111
|
||||||
|
```
|
||||||
|
|
||||||
|
To mount it automatically on WSL start, add the following lines to `/etc/fstab`:
|
||||||
|
|
||||||
|
```fstab
|
||||||
|
<drive_letter>: /mnt/<drive_letter> drvfs metadata,umask=022,fmask=0111 0 0
|
||||||
|
```
|
||||||
|
|
||||||
|
Reload fstab:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo mount -a
|
||||||
|
```
|
||||||
|
|
||||||
|
Remove others write permissions in your project folder:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo chmod -R o-w .
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Install Ansible on WSL:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install ansible ssh-askpass
|
||||||
|
```
|
||||||
|
|
||||||
|
Add SSH Keys from Windows to WSL:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp -r /mnt/c/Users/<username>/.ssh ~/.ssh
|
||||||
|
chmod 700 ~/.ssh
|
||||||
|
chmod 600 ~/.ssh/id_rsa
|
||||||
|
chmod 644 ~/.ssh/id_rsa.pub
|
||||||
|
```
|
||||||
|
|
||||||
|
Lastly, restart WSL to apply the changes:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
sudo shutdown -r now
|
||||||
|
```
|
||||||
|
|||||||
5
ansible.cfg
Normal file
5
ansible.cfg
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[defaults]
|
||||||
|
inventory = ./inventory/inventory.yml
|
||||||
|
host_key_checking = False
|
||||||
|
interpreter_python = auto_silent
|
||||||
|
nocows=1
|
||||||
24
inventory/inventory.example.yml
Normal file
24
inventory/inventory.example.yml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
all:
|
||||||
|
vars:
|
||||||
|
ansible_user: root
|
||||||
|
hosts:
|
||||||
|
proxmox-host:
|
||||||
|
ansible_host: 192.168.1.1
|
||||||
|
virtual-machine:
|
||||||
|
ansible_host: 192.168.1.2
|
||||||
|
container-host:
|
||||||
|
ansible_host: 192.168.1.3
|
||||||
|
|
||||||
|
pve:
|
||||||
|
hosts:
|
||||||
|
proxmox-host:
|
||||||
|
|
||||||
|
vms:
|
||||||
|
hosts:
|
||||||
|
virtual-machine:
|
||||||
|
vars:
|
||||||
|
ansible_user: user
|
||||||
|
|
||||||
|
cts:
|
||||||
|
hosts:
|
||||||
|
container-host:
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
- hosts: all
|
---
|
||||||
become: yes
|
- name: Update apt packages
|
||||||
|
hosts: all
|
||||||
|
become: true
|
||||||
tasks:
|
tasks:
|
||||||
- name: Update apt packages
|
- name: Update apt packages
|
||||||
apt:
|
apt:
|
||||||
upgrade: yes
|
|
||||||
update_cache: yes
|
update_cache: yes
|
||||||
|
upgrade: dist
|
||||||
|
|
||||||
- name: Check if reboot is needed
|
- name: Check if reboot is needed
|
||||||
stat:
|
stat:
|
||||||
@@ -19,3 +21,8 @@
|
|||||||
user_key: '{{ user_key }}'
|
user_key: '{{ user_key }}'
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
when: reboot_required.stat.exists
|
when: reboot_required.stat.exists
|
||||||
|
|
||||||
|
- name: Give reboot notification
|
||||||
|
ansible.builtin.debug:
|
||||||
|
msg: "Reboot is required on {{ inventory_hostname }}"
|
||||||
|
when: reboot_required.stat.exists
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
- hosts: all
|
---
|
||||||
|
- name: Get disk space usage
|
||||||
|
hosts: all
|
||||||
tasks:
|
tasks:
|
||||||
- name: Get disk usage
|
- name: Get disk usage
|
||||||
shell: df -h / | awk 'NR==2 {print $5}'
|
shell: df -h / | awk 'NR==2 {print $5}'
|
||||||
Reference in New Issue
Block a user