# Ansible playbook for updating Discourses

**URL:** <https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268>\
**Category:** Sysadmins\
**Tags:** explanation\
**Created:** [6월 1, 2019, 10:01오전 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268 "2019-06-01T10:01:07Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)\
**Post date:** [6월 1, 2019, 10:01오전 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/1 "2019-06-01T10:01:07Z")

</div>

Hi Meta,

While there seem to be a few playbooks around for provisioning Discourse, there didn’t seem to be any for doing updates/upgrades, so in response to my own personal need I’ve created one.

[https://github.com/pacharanero/ansible-discourse](https://github.com/pacharanero/ansible-discourse)

Very happy to receive feedback, bug reports, pull requests, etc.

---

<div class="post-metadata">

**Author:** ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)\
**Post date:** [6월 1, 2019, 5:45오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/2 "2019-06-01T17:45:12Z")

</div>

It looks interesting, now, I have a few observations, that I think can help to improve the playbook.

- Why always use `dist-upgrade`? It would be safer just to use `apt upgrade` and leave the `apt dist-upgrade` for manual intervention, to ensure nothing breaks.
- Using `autoremove` and `autoclean` can bring some headaches with over enthusiastic packages removal.
- `cd /var/discourse && git pull ` although nice, not needed. My understanding is that `./launcher rebuild app` already does the `git pull`.

I think the playbook could get a lot more powerful using variables, like choosing which upgrade process will be used. Adding conditionals for `autoremove` and `autoclean`. As well for the rebooting as it’s not always needed.

---

<div class="post-metadata">

**Author:** ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)\
**Post date:** [6월 1, 2019, 6:38오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/3 "2019-06-01T18:38:22Z")

</div>

Thanks @marianord for your feedback. You make valid points.

I’ve been using `apt dist-upgrade` for years on all my servers without any issues or breaking anything. I found [this answer](https://askubuntu.com/questions/194651/why-use-apt-get-upgrade-instead-of-apt-get-dist-upgrade) on AskUbuntu, which was helpful in understanding the difference, and it didn’t seem to suggest any major risks to `dist-upgrade`. I am not using any special PPAs or apt pinning on any of my instances.

`autoremove` and `autoclean` are things I do periodically on my servers, and I wasn’t sure how frequently they should ideally be done, so I just figured do it at the end of each OS upgrade. Anyone know how often this should be done?

As for `git pull` I have always done this because the Discourse upgrade instructions say to do it. I can see there is a `git pull` going on in the ./launcher script but I assumed some of that was going on _inside_ the Docker container, so you might also need a `git pull` outside the container to update the docker manager code?

---

<div class="post-metadata">

**Author:** ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)\
**Post date:** [6월 1, 2019, 6:52오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/4 "2019-06-01T18:52:45Z")

</div>

The possible issue (is not common, but possible) is that by using anything else than `apt upgrade` you might break something else. Assuming you’d like a broader public to use that playbook giving the choice of using `upgrade` or `dist-upgrade` is a nice to have. I’d default it to `apt upgrade` and enable a variable to change it to `apt dist-upgrade`.

Why? Because `apt upgrade` is the only command that ensures it won’t break something upgrading other things. For example, let’s say someone is running Discourse with nginx as a reverse proxy. And for some hypothetical reason both nginx and Docker (or Redis, PostgreSQL, etc) use `libhypothetical`. Nginx doesn’t update it to the lastest version, but that other package does. If the library made breaking changes Nginx will stop working if the system is updated with anything else than `apt upgrade`, bringing the service down.

The issue with `autoremove` and `autoclean` is the same one as with `apt dist-upgrade`, if `libhypothetical` is a dependency of two packages, one updates and doesn’t needs it anymore `apt` might fail to know that the other package still needs it and remove it. Having old packages, for me, is not that big of an issue as they don’t usually take more than a couple hundred megabytes, until I get in there manually and remove them.

My understanding is that they updated the `.launcher rebuild` command and added the `git pull` that wasn’t there before. But people more knowledgeable about that can tell us definitively.

---

<div class="post-metadata">

**Author:** ![featheredtoast](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/featheredtoast/32/116994_2.png) [@featheredtoast](https://meta.discourse.org/u/featheredtoast)\
**Post date:** [6월 1, 2019, 11:06오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/5 "2019-06-01T23:06:13Z")

</div>

> [@marianord](#):
>
> rebooting as it’s not always needed.

I’m in agreement above, the reboot seems unnessary and fairly dangerous to have in a script like this. In situations where the ansible script were automated, could be surprising if a user doing manual work on the server were kicked out for a reboot.

---

<div class="post-metadata">

**Author:** ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)\
**Post date:** [6월 2, 2019, 11:11오전 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/6 "2019-06-02T11:11:04Z")

</div>

OK thanks @featheredtoast and @marianord

About half the time when I do updates on servers, the next time I log in the MOTD is ‘A reboot is required’, so I had decided that rebooting would probably be necessary most times I run the update.

Very easy to have two playbooks, one which does `dist-upgrade`, `autoclean` and `reboot` and one which does just plain `upgrade`, no `autoclean`, and no `reboot`, maybe?

I tend to trigger these playbooks manually, and watch the output, so they are not running on a `cron` job or on a daily basis, which I would agree is risky in terms of rebooting in the middle of work.

Note that due to the way Discourse works with client-side Ember code, users can be in the middle of writing a reply when the server reboots and they will probably not notice any interruption. Reboots take less than 15secs usually in my setup.

---

<div class="post-metadata">

**Author:** ![marianord](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/marianord/32/90502_2.png) [@marianord](https://meta.discourse.org/u/marianord)\
**Post date:** [6월 2, 2019, 3:41오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/7 "2019-06-02T15:41:43Z")

</div>

You can make it work with just one playbook using conditionals. And some more variables

---

<div class="post-metadata">

**Author:** ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)\
**Post date:** [6월 2, 2019, 6:47오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/8 "2019-06-02T18:47:10Z")

</div>

Ansible is very flexible and I’m quite sure it is possible with conditionals. Happy to take a PR although I don’t want to overcomplicate what is a very simple playbook.

Overall I’m just looking for a playbook that suits my personal needs and I thought I’d share it with the rest of the Discourse community in case it helped anyone.

Maybe we could pool our ideas and make a suite of Ansible tools for managing and provisioning Discourses using Ansible (which seems to me the most lightweight tool for this purpose) which includes a variety of playbooks

---

<div class="post-metadata">

**Author:** ![chrisc](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/chrisc/32/119982_2.png) [@chrisc](https://meta.discourse.org/u/chrisc)\
**Post date:** [10월 13, 2019, 10:14오전 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/9 "2019-10-13T10:14:46Z")

</div>

또한 [몇 년 전의 이 스레드](https://meta.discourse.org/t/ansible-playbook-to-install-docker-discourse-and-postfix/62496)를 참고하세요. 제가 Discourse용으로 작성한 Ansible은 오랫동안 업데이트되지 않았지만, 곧 시간을 내어 개선할 수 있기를 바랍니다.

---

<div class="post-metadata">

**Author:** ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)\
**Post date:** [10월 4, 2024, 7:10오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/10 "2024-10-04T19:10:38Z")

</div>

> [@pacharanero](#):
>
> [https://github.com/pacharanero/ansible-discourse-updater](https://github.com/pacharanero/ansible-discourse-updater)

지금 이 링크가 404 오류를 반환하고 있습니다. 이전된 건가요?

---

<div class="post-metadata">

**Author:** ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)\
**Post date:** [10월 4, 2024, 8:12오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/11 "2024-10-04T20:12:50Z")

</div>

> [@jericson](#):
>
> 이동한 건가요?

저는 [https://github.com/bawmedical/ansible-tools/blob/main/playbooks/discourse-updater-playbook.yml](https://github.com/bawmedical/ansible-tools/blob/main/playbooks/discourse-updater-playbook.yml) 로 옮긴 것 같습니다. 하지만 만족할 만한 단계까지 도달하지는 못했습니다. 결국 Ansible을 포기하고 Bash 스크립트를 사용하게 되었습니다.

수동으로 OS와 Discourse 업데이트를 하는 데 상당한 시간이 걸리기 때문에, 진지하게 Discourse 호스팅을 하는 사람들이 어떤 방식을 취하고 있는지 궁금합니다.

---

<div class="post-metadata">

**Author:** ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)\
**Post date:** [10월 4, 2024, 8:34오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/12 "2024-10-04T20:34:58Z")

</div>

> [@pacharanero](#):
>
> [https://github.com/bawmedical/ansible-tools/blob/main/playbooks/discourse-updater-playbook.yml](https://github.com/bawmedical/ansible-tools/blob/main/playbooks/discourse-updater-playbook.yml)

저에게도 404 오류가 발생합니다. 비공개 저장소일까요?

> [@pacharanero](#):
>
> 결국 만족할 만한 단계까지 도달하지 못했습니다. 결국 Ansible을 포기하고 Bash 스크립트를 사용하기로 했습니다.

이해합니다. 저는 [Discourse 설치용 플레이북](https://beta.buildcivitas.com/t/staging-server-for-discourse-hosting/112)을 가지고 있었고, 다른 사람들이 이 문제를 어떻게 접근하는지 궁금했습니다. 말씀하신 대로 업데이트를 따라가는 것은 시간이 많이 걸리는 일이죠.

---

<div class="post-metadata">

**Author:** ![pacharanero](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pacharanero/32/500583_2.png) [@pacharanero](https://meta.discourse.org/u/pacharanero)\
**Post date:** [10월 4, 2024, 8:51오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/13 "2024-10-04T20:51:29Z")

</div>

아 죄송합니다, 네, 프라이빗 저장소입니다. 저는 거의 그런 일을 하지 않거든요! 아마도 그 작업의 쓸모없음에 대해 부끄러웠던 것 같습니다… 🤣

해당 파일은 다음과 같습니다:

```plaintext
---
- hosts: all
  vars:
    ansible_python_interpreter: auto_silent

  tasks:
  - name: Update server OS (apt update && apt dist-upgrade && apt autoremove && apt autoclean)
    become: yes
    apt:
      update-cache: yes
      upgrade: dist
      autoremove: yes
      autoclean: yes

  # - name: Update Discourse code from GitHub (cd /var/discourse && git pull)
  # become: yes
  # git:
  # repo: 'https://github.com/discourse/discourse_docker.git'
  # dest: /var/discourse
  # update: yes
  # version: master
  # register: gitcommit

  # - name: Rebuild the Discourse container (cd /var/discourse && ./launcher rebuild app)
  # become: yes
  # shell: ./launcher rebuild app
  # args:
  # chdir: /var/discourse
  # when: gitcommit.changed

  # - name: Clean up stopped containers (cd /var/discourse && ./launcher cleanup)
  # become: yes
  # shell: echo Y | ./launcher cleanup
  # args:
  # chdir: /var/discourse

  # - name: Reboot machine with default Ansible settings
  # reboot:
  # become: yes

```

보시다시피, 현재 상태로는 거의 쓸모없는 수준입니다.

OS 업데이트, Discourse 업데이트, 런처 클린업 및 (보너스 포인트로) 각 Discourse 인스턴스의 Changelog에 기록하는 기능을 자동화하기 위한 공유 스크립트 개발에 관심이 있다면, 저는 도와줄 의향이 있습니다. 저 혼자서라면 제 자신의 Ansible 플레이북을 유지보수하는 것이 그다지 가치 있다고 생각되지 않습니다.

---

<div class="post-metadata">

**Author:** ![jericson](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jericson/32/116215_2.png) [@jericson](https://meta.discourse.org/u/jericson)\
**Post date:** [10월 4, 2024, 9:14오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/14 "2024-10-04T21:14:23Z")

</div>

조금 관심이 있습니다. 저는 #two-container 구성을 사용하므로, 그에 맞춰 조정해야 합니다. 또한 재부팅을 선택 사항으로 만들고 싶습니다. 불가능한 것은 없어 보이지만, 여러 명이 함께 하면 개인에게 부담이 덜 될 것입니다.

---

<div class="post-metadata">

**Author:** ![RGJ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/rgj/32/523185_2.png) [@RGJ](https://meta.discourse.org/u/RGJ)\
**Post date:** [10월 4, 2024, 9:24오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/15 "2024-10-04T21:24:31Z")

</div>

> [@pacharanero](#):
>
> 진지하게 디스커스를 호스팅하는 사람들이 어떤 방식을 사용하고 있는지 궁금합니다.

Communiteq에서는 모든 작업에 Ansible을 사용합니다.

---

<div class="post-metadata">

**Author:** ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)\
**Post date:** [10월 7, 2024, 6:49오후 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/16 "2024-10-07T18:49:11Z")

</div>

Literate Computing은 모든 작업에 Ansible을 사용합니다.

> [@jericson](#):
>
> 저는 #two-container 설정을 사용하고 있으므로, 이를 고려해야 합니다.

[https://dashboard.literatecomputing.com/](https://dashboard.literatecomputing.com/) 을 사용하시면 제 Ansible 스크립트를 사용할 수 있습니다(확인할 수는 없지만). 이 도구는 2-컨테이너 설정을 인지하며, Postgres 버전과 pgvector 버전을 확인하고, 디스크 공간이 부족해지면 클리업 작업을 실행하는 등 다양한 기능을 제공합니다. Free Trial 그룹에 가입하면 무료로 체험해 볼 수 있습니다.

---

<div class="post-metadata">

**Author:** ![nathank](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nathank/32/290039_2.png) [@nathank](https://meta.discourse.org/u/nathank)\
**Post date:** [10월 10, 2024, 2:50오전 UTC](https://meta.discourse.org/t/ansible-playbook-for-updating-discourses/119268/17 "2024-10-10T02:50:45Z")

</div>

> [@RGJ](#):
>
> Communiteq에서는 모든 작업에 Ansible을 사용합니다.

> [@pfaffman](#):
>
> Literate Computing 역시 모든 작업에 Ansible을 사용합니다.

[Discourse 포럼](https://forum.ansible.com/)을 운영하고 있다는 점이 좋습니다. 보통 이는 좋은 오픈소스 프로젝트의 신호입니다.
