---

- name: Update pacman website
  hosts: localhost
  vars:
      pacman_version: "5.2.2"
      archweb_dir: '/srv/http/archweb'
  tasks:
      - name: Create temp dir
        tempfile: state=directory suffix=pacman
        register: tempdir

      - name: fetch pacman tarball
        get_url: url=https://sources.archlinux.org/other/pacman/pacman-{{ pacman_version }}.tar.gz dest={{ tempdir.path }}/pacman.tar.gz

      - name: create extraction dir
        file: path={{ tempdir.path }}/pacman state=directory owner=root group=root mode=0755

      - name: unpack tarball
        unarchive: src={{ tempdir.path }}/pacman.tar.gz dest={{ tempdir.path }}/pacman/ owner=root group=root mode=0755

      - name: configure
        command: ./configure chdir={{ tempdir.path }}/pacman/pacman-{{ pacman_version }}
        register: configure
        changed_when: "configure.rc == 0"

      - name: make
        make: chdir={{ tempdir.path }}/pacman/pacman-{{ pacman_version }}/doc target=website

      - name: upload website
        unarchive: src={{ tempdir.path }}/pacman/pacman-{{ pacman_version }}/doc/website.tar.gz dest={{ archweb_dir }}/archlinux.org/pacman mode=0644
        delegate_to: archlinux.org
