Latest pkg in FreeBSD

Updated

Another note to future me - an Ansible role for enabling the latest repository for FreeBSD pkgng.

  ---
  - name: "Prepare directory"
    ansible.builtin.file:
      path: "{{ item }}"
      state: directory
    with_items:
      - /usr/local/etc/pkg/
      - /usr/local/etc/pkg/repos/

  - name: "Prepare latest.conf"
    ansible.builtin.file:
      path: /usr/local/etc/pkg/repos/latest.conf
      state: touch

  - name: "Setup pkg to use the latest repo"
    ansible.builtin.blockinfile:
      path: /usr/local/etc/pkg/repos/latest.conf
      block: |
                FreeBSD: { url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest" }
    register: new_repo

  - name: "Update repo"
    ansible.builtin.command:
      argv:
        - "pkg"
        - "-y"
        - "update"
    when: new_repo.changed

  - name: "Upgrade all packages"
    community.general.pkgng:
      name: "*"
      state: latest

Bonus - a shell oneliner

  mkdir -p /usr/local/etc/pkg/repos && cat << EOF > /usr/local/etc/pkg/repos/latest.conf
  FreeBSD: { url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest" }
  EOF