|
| 1 | + |
| 2 | + |
| 3 | +# infra/vps |
| 4 | + |
| 5 | +## requirements |
| 6 | + |
| 7 | +- a linux server (debian) with ssh enabled and you have sudo privilege |
| 8 | +- have Ansible installed on local machine |
| 9 | + - macOS: `brew install ansible` |
| 10 | + |
| 11 | +## `inventory.ini` file |
| 12 | + |
| 13 | +create a `inventory.ini` file at the root of this directory |
| 14 | +and fill it out with your server's information: |
| 15 | + |
| 16 | +- server url |
| 17 | +- linux user's username |
| 18 | + |
| 19 | +__don't commit this file with your private information__ |
| 20 | + |
| 21 | +``ìni |
| 22 | +[linux_vps] |
| 23 | +<my_server.com> ansible_user=<my_server_username> |
| 24 | + |
| 25 | +``` |
| 26 | +
|
| 27 | +## ansible update debian server |
| 28 | +
|
| 29 | +play only the check tasks to list what packages are getting upgraded |
| 30 | +
|
| 31 | +```bash |
| 32 | +ansible-playbook --tags check --ask-become-pass update_debian.yml |
| 33 | +``` |
| 34 | + |
| 35 | +perform the upgrade |
| 36 | + |
| 37 | +```bash |
| 38 | +ansible-playbook --ask-become-pass update_debian.yml |
| 39 | +``` |
| 40 | + |
| 41 | +## ansible installs and configure postgresql database on Debian server |
| 42 | + |
| 43 | +### test connection to vps first |
| 44 | + |
| 45 | +```bash |
| 46 | +ansible -i inventory.ini linux_vps -m ping |
| 47 | + |
| 48 | +# expect success |
| 49 | +``` |
| 50 | + |
| 51 | +### sensitive value in versionned file |
| 52 | + |
| 53 | +we are using `ansible-vault` command-line tool to create, encrypt, decrypt, and |
| 54 | +safely use versionned secrets in files |
| 55 | + |
| 56 | +```bash |
| 57 | +# create a new encrypted secrets file |
| 58 | +ansible-vault create | edit <file_name>.yml |
| 59 | + |
| 60 | +# will open a vi editor where you you can edit key-value (ini style) secrets |
| 61 | +``` |
| 62 | + |
| 63 | +### run the playbook with the Vault password |
| 64 | + |
| 65 | +Runs the playbook |
| 66 | + |
| 67 | +- will prompt `BECOME` for your server 'sudo' password |
| 68 | +- will prompt `Vault password` for your secret file (ansible-vault) password |
| 69 | + |
| 70 | +```bash |
| 71 | +ansible-playbook \ |
| 72 | + --ask-vault-pass \ |
| 73 | + --ask-become-pass \ |
| 74 | + install_postgresql.yml |
| 75 | +``` |
| 76 | + |
| 77 | +## from local machine |
| 78 | + |
| 79 | +postgresql database is only available from server's localhost network |
| 80 | + |
| 81 | +### ssh tunnel from local machine to server |
| 82 | + |
| 83 | +in order to connect to it from an IDE like DBeaver, establish an ssh tunnel |
| 84 | +(leave the terminal open to keep connection open) |
| 85 | + |
| 86 | +```bash |
| 87 | +ssh -L 5432:localhost:5432 [email protected] |
| 88 | +``` |
| 89 | + |
| 90 | +### DBeaver IDE |
| 91 | + |
| 92 | +| host | Database | authentitification | username | password | |
| 93 | +| --------- | -------- | ------------------ | -------- | ------------------- | |
| 94 | +| localhost | devdb | Database native | devuser | `<db_password.yml>` | |
0 commit comments