auberge 0.8.1

CLI tool for managing self-hosted infrastructure with Ansible
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# CI/CD Automation

Guide to automating Auberge deployments with CI/CD pipelines.

## Overview

Auberge supports fully automated deployments via the `--force` flag, which skips interactive prompts while still displaying warnings.

**Key features:**

- Skip confirmation prompts
- Explicit host and playbook selection
- Warning messages always displayed
- Exit codes for pipeline integration

## The --force Flag

### What It Does

`--force` (or `-f`) skips interactive confirmations:

```bash
# With --force: no prompts
auberge ansible run --host production --playbook playbooks/apps.yml --force

# Without --force: prompts for confirmation
auberge ansible run --host production --playbook playbooks/apps.yml
# ? Confirm execution? [y/N]:
```

### What It Doesn't Do

**--force does NOT skip warnings:**

```bash
auberge ansible bootstrap production --ip 10.0.0.1 --force
```

**Output:**

```
⚠ WARNING: Ensure provider firewall allows SSH_PORT (2222)
⚠ WARNING: Bootstrap will change SSH port from 22 to 2222
⚠ WARNING: Ensure Cloudflare API token is configured

Proceeding with bootstrap...
```

**Warnings always display** - you're responsible for heeding them.

## GitHub Actions

### Complete Workflow Example

```yaml
name: Deploy to VPS

on:
  push:
    branches: [main]
  workflow_dispatch: # Manual trigger

permissions:
  contents: read

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Install Rust
        uses: dtolnay/rust-toolchain@stable

      - name: Install Auberge
        run: cargo install auberge

      - name: Configure secrets
        env:
          SSH_PORT: ${{ secrets.SSH_PORT }}
          ADMIN_USER_NAME: ${{ secrets.ADMIN_USER_NAME }}
          CLOUDFLARE_DNS_API_TOKEN: ${{ secrets.CLOUDFLARE_DNS_API_TOKEN }}
        run: |
          auberge config init
          auberge config set ssh_port "$SSH_PORT"
          auberge config set admin_user_name "$ADMIN_USER_NAME"
          auberge config set cloudflare_dns_api_token "$CLOUDFLARE_DNS_API_TOKEN"

      - name: Set up SSH key
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
        run: |
          mkdir -p ~/.ssh/identities
          echo "$SSH_PRIVATE_KEY" > ~/.ssh/identities/ansible_production
          chmod 600 ~/.ssh/identities/ansible_production

      - name: Deploy applications
        run: |
          auberge ansible run \
            --host production \
            --playbook playbooks/apps.yml \
            --force \
            --skip-tags bootstrap

      - name: Verify deployment
        run: |
          ssh -i ~/.ssh/identities/ansible_production \
              -p ${{ secrets.SSH_PORT }} \
              ansible@${{ secrets.AUBERGE_HOST }} \
              "systemctl is-active baikal freshrss navidrome"
```

### Required GitHub Secrets

Set these in repository settings → Secrets and variables → Actions:

- `SSH_PORT` - Custom SSH port
- `SSH_PRIVATE_KEY` - ansible user's SSH private key (full content)
- `ADMIN_USER_NAME` - Admin username
- `CLOUDFLARE_DNS_API_TOKEN` - Cloudflare API token
- Other app-specific secrets (BAIKAL_ADMIN_PASSWORD, etc.)

## GitLab CI

### .gitlab-ci.yml

```yaml
stages:
  - deploy

deploy_production:
  stage: deploy
  image: rust:latest
  only:
    - main
  before_script:
    - cargo install auberge
    - mkdir -p ~/.ssh/identities
    - echo "$SSH_PRIVATE_KEY" > ~/.ssh/identities/ansible_production
    - chmod 600 ~/.ssh/identities/ansible_production
    - auberge config set ssh_port "$SSH_PORT"
    - auberge config set admin_user_name "$ADMIN_USER_NAME"
    - auberge config set cloudflare_dns_api_token "$CLOUDFLARE_DNS_API_TOKEN"
  script:
    - auberge ansible run
      --host production
      --playbook playbooks/apps.yml
      --force
      --skip-tags bootstrap
  after_script:
    - ssh -i ~/.ssh/identities/ansible_production
      -p $SSH_PORT
      ansible@$AUBERGE_HOST
      "systemctl status php*-fpm freshrss navidrome"
```

### Required GitLab Variables

Set in Settings → CI/CD → Variables:

- `SSH_PORT`
- `SSH_PRIVATE_KEY` (masked, file type)
- `ADMIN_USER_NAME`
- `CLOUDFLARE_DNS_API_TOKEN` (masked)

## Best Practices

### Use Separate Environments

```yaml
# .github/workflows/deploy-staging.yml
- name: Deploy to staging
  run: |
    auberge ansible run \
      --host staging \
      --playbook playbooks/apps.yml \
      --force

# .github/workflows/deploy-production.yml
- name: Deploy to production
  run: |
    auberge ansible run \
      --host production \
      --playbook playbooks/apps.yml \
      --force
```

### Create Backup Before Deploy

```yaml
- name: Create backup
  run: |
    auberge backup create --host production --yes

- name: Deploy
  run: |
    auberge ansible run \
      --host production \
      --playbook playbooks/apps.yml \
      --force

- name: Verify deployment
  run: |
    # Health checks
    curl -f https://cal.example.com || exit 1
```

### Use Check Mode First

```yaml
- name: Check what would change
  run: |
    auberge deploy \
      --all \
      --host production \
      --check \
      --force

- name: Deploy if check passed
  run: |
    auberge deploy \
      --all \
      --host production \
      --force
```

### Tag-Based Deployments

```yaml
- name: Deploy only changed apps
  run: |
    # Detect which apps changed
    CHANGED_APPS=$(git diff --name-only HEAD~1 | grep 'ansible/roles/' | cut -d'/' -f3 | tr '\n' ',' | sed 's/,$//')

    if [ -n "$CHANGED_APPS" ]; then
      auberge ansible run \
        --host production \
        --tags "$CHANGED_APPS" \
        --force
    else
      echo "No app changes detected"
    fi
```

### Rollback on Failure

```yaml
- name: Deploy
  id: deploy
  run: |
    auberge ansible run \
      --host production \
      --playbook playbooks/apps.yml \
      --force

- name: Rollback on failure
  if: failure() && steps.deploy.conclusion == 'failure'
  run: |
    auberge backup restore latest \
      --host production \
      --yes
```

## Security Considerations

### Protect SSH Keys

**Never commit SSH private keys** to version control.

✓ **Good:** Use GitHub Secrets or GitLab Variables
✗ **Bad:** Store in repository

### Use Deploy Keys

Generate dedicated SSH keys for CI/CD:

```bash
# On CI runner or locally
ssh-keygen -t ed25519 -f ~/.ssh/ci_deploy_key -C "ci-deploy@example.com"

# Add public key to VPS
ssh-copy-id -i ~/.ssh/ci_deploy_key.pub ansible@vps-host
```

Add private key to CI secrets:

```bash
cat ~/.ssh/ci_deploy_key  # Copy to GitHub Secrets
```

### Restrict Runner Permissions

Use least-privilege principles:

```yaml
permissions:
  contents: read # Don't grant write unless needed
```

### Audit Deployments

Log all deployments:

```yaml
- name: Log deployment
  run: |
    echo "Deployed by: ${{ github.actor }}"
    echo "Commit: ${{ github.sha }}"
    echo "Branch: ${{ github.ref }}"
    date
```

## Testing in CI

### Ansible Syntax Check

```yaml
- name: Check Ansible syntax
  run: |
    cd ansible && ansible-playbook playbooks/apps.yml --syntax-check
```

### Lint Playbooks

```yaml
- name: Lint Ansible playbooks
  run: |
    ansible-lint playbooks/
```

### Validate Inventory

```yaml
- name: Validate inventory
  run: |
    ansible-inventory -i ansible/inventory.yml --list
```

## Deployment Strategies

### Blue-Green Deployment

Maintain two VPS hosts:

```yaml
- name: Deploy to blue
  run: |
    auberge ansible run --host blue --playbook playbooks/apps.yml --force

- name: Switch DNS to blue
  run: |
    auberge dns set-all --host blue --force

- name: Drain green
  run: |
    # Wait for connections to drain
    sleep 300

- name: Update green
  run: |
    auberge ansible run --host green --playbook playbooks/apps.yml --force
```

### Canary Deployment

Deploy to subset of hosts first:

```yaml
- name: Deploy to canary
  run: |
    auberge ansible run --host canary --playbook playbooks/apps.yml --force

- name: Smoke test
  run: |
    curl -f https://cal.canary.example.com || exit 1

- name: Deploy to production
  run: |
    auberge ansible run --host production --playbook playbooks/apps.yml --force
```

## Monitoring Deployments

### Send Notifications

```yaml
- name: Notify on success
  if: success()
  run: |
    curl -X POST $WEBHOOK_URL \
      -d "Deployment to production succeeded"

- name: Notify on failure
  if: failure()
  run: |
    curl -X POST $WEBHOOK_URL \
      -d "Deployment to production failed"
```

### Log to External Service

```yaml
- name: Log deployment
  run: |
    curl -X POST https://logging-service.example.com/events \
      -H "Content-Type: application/json" \
      -d '{
        "event": "deployment",
        "status": "success",
        "commit": "${{ github.sha }}",
        "actor": "${{ github.actor }}"
      }'
```

## Example: Minimal Production Pipeline

```yaml
name: Deploy to Production

on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - run: cargo install auberge

      - name: Set up SSH
        env:
          SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
        run: |
          mkdir -p ~/.ssh/identities
          echo "$SSH_KEY" > ~/.ssh/identities/ansible_production
          chmod 600 ~/.ssh/identities/ansible_production

      - name: Configure
        env:
          SSH_PORT: ${{ secrets.SSH_PORT }}
          CLOUDFLARE_DNS_API_TOKEN: ${{ secrets.CLOUDFLARE_DNS_API_TOKEN }}
        run: |
          auberge config set ssh_port "$SSH_PORT"
          auberge config set cloudflare_dns_api_token "$CLOUDFLARE_DNS_API_TOKEN"

      - name: Deploy
        run: |
          auberge ansible run \
            --host production \
            --playbook playbooks/apps.yml \
            --force \
            --skip-tags bootstrap
```

## Troubleshooting

### SSH Host Key Verification Failed

Add host key to known_hosts:

```yaml
- name: Add host key
  run: |
    ssh-keyscan -p ${{ secrets.SSH_PORT }} ${{ secrets.AUBERGE_HOST }} >> ~/.ssh/known_hosts
```

### Config Values Not Set

Ensure config is properly written:

```yaml
- name: Debug config
  run: |
    auberge config list
```

### Permission Denied (SSH)

Check SSH key permissions:

```yaml
- run: chmod 600 ~/.ssh/identities/ansible_production
```

### Ansible Connection Timeout

Increase timeout in inventory:

```yaml
ansible_ssh_common_args: >-
  -o ConnectTimeout=30
  -o ConnectionAttempts=3
```

## Related Pages

- [Running Playbooks]deployment/running-playbooks.md - Manual execution
- [Bootstrap]deployment/bootstrap.md - Initial VPS setup
- [Secrets Management]configuration/secrets.md - Handling sensitive data
- [SSH Keys]configuration/ssh-keys.md - SSH configuration