This page looks best with JavaScript enabled

How to upgrade Portainer on a remote host using Ansible

 ·  ☕ 1 min read  ·  🐧 sysadmin

How to upgrade Portainer using Ansible

  1. Here is a video tutorial

Requirements for Ansible:

  • ansible user added to each remote node
  • ansible user added to sudo/wheel/admins group
  • sudo/wheel/admins group set in /etc/sudoers to perform command with elevated privileges
  1. Create ansible inventory
1
sudo vim /etc/ansible/hosts
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
all:
  children:
    portainer:
      hosts:
        AdGuard:
          ansible_host: 10.10.0.108
          ansible_user: ansible
        nginx-proxy-manager:
          ansible_host: 10.10.0.137 
          ansible_user: ansible
  1. Create ansible playbook. See the video for the explanation.
1
vim portainer.yml 
  1. Put the below content into this file.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
---
- name: Upgrade Portainer on AdGuard Home LXC container in Proxmox
  hosts: portainer
  become: yes
  tasks:
    - name: Stop Portainer
      shell: docker stop portainer 

    - name: Remove Portainer
      shell: docker rm portainer

    - name: Create the volume that Portainer Server will use to store its database
      shell: docker volume create portainer_data

    - name: Download newest Portainer 
      shell: sudo docker pull portainer/portainer-ce:latest 

    - name: Run Portainer 
      shell: docker run -d -p 8000:8000 -p 9443:9443 --name=portainer --restart=always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer-ce:latest
  1. Run the playbook like below:
1
ansible-playbook portainer.yml
Scripts and configuration files are available here:
Share on

sysadmin
WRITTEN BY
sysadmin
QA & Linux Specialist