Automating Ejabberd upgrade procedure with Ansible ·
another meaningless subtitle

Automating Ejabberd upgrade procedure with Ansible

· by fabio · Read in about 2 min · (378 Words)
bash CentOS 7 ejabberd

CentOS repos (both official and EPEL) does not provide an up to date version of Ejabberd, installing from source is the only way if one want or need a version from this century.
Problem is that doing things manually is a never ever a good idea, luckily Ansible and a bit of Python love come to rescue.
Supposing Ejabberd is already installed and configured (I wrote a post on the subject a couple of years ago: the following Ansible script will take care of all the steps needed to upgrade to a newer version of Ejabberd

.:. centos7-upgrade-ejabberd.yml

- hosts: ejabberd
    local_conf_path: /home/user/ansible-playbook-scripts/
    remote_src_path: /home/user/binaries/ejabberd/
    remote_etc_path: /usr/local/etc/ejabberd/
  user: root
      - fetch:
          src: "{{ remote_etc_path }}ejabberd.yml"
          flat: yes
          dest: "{{ local_conf_path }}"
      - name: Create directory structure
        command: mkdir -p {{ remote_src_path }}
      - name: Rotate directories
        command: chdir={{ remote_src_path }} {{ item }} 
            - rm -rf ejabberd_old
            - cp -r ejabberd ejabberd_old
        ignore_errors: True      
      - name: Upload git script
        template: owner=root group=root mode=755 src={{ local_conf_path }} dest={{ remote_src_path }}
      - name: Run upgrade script
        command: /usr/bin/sh /{{ remote_src_path }}ejabberd/
      - name: Compile latest
        command: chdir={{ remote_src_path }}ejabberd/ {{ item }}
            - sh
            - ./configure --enable-user=ejabberd --disable-graphics
            - make distclean
            - sh
            - ./configure --enable-user=ejabberd --disable-graphics
            - make
      - name: Stop ejabberd service CentOS 7
        command: "{{ item }}"
            - systemctl stop ejabberd
            - /bin/sleep 20
        ignore_errors: True
      - name: Uninstall old
        command: chdir={{ remote_src_path }}ejabberd_old/ {{ item }}
            - ./configure --enable-user=ejabberd --disable-graphics
            - make uninstall
            - rm -rf /usr/local/lib/*
        ignore_errors: True
      - name: Install latest
        command: chdir={{ remote_src_path }}ejabberd/ make install
        #    - enable ejabberd
      - name: Create ejabberd-0.0 directory
        command: chdir=/usr/local/lib/ cp -r ejabberd* ejabberd-0.0
        ignore_errors: True
      - name: Start ejabberd service 
        command: systemctl start ejabberd

      - name: enable ejabberd
        service: name=ejabberd.service enabled=yes


The easiest method of fetching the latest version of Ejabberd is via git tags, I could not make it directly in Ansible (there might be a way tho) I wrote a small bash script to do it for me.


cd /home/fabio/binaries/ejabberd/ejabberd/
make distclean
git fetch --tags
latestTag=$(git describe --tags $(git rev-list --tags --max-count=1))
echo $latestTag > ./version.txt
git checkout $latestTag

To execute an Ansible playbook simply run:

ansible-playbook centos7-upgrade-ejabberd.yml