Ansible role for opam management

Hi everyone !
I’m currently working on an ansible role to manage the installation of opam and specified switches. My use case is to install opam, some specified switches and configure them on a fleet of machines in my CS lab, but I tried to generalize a bit from there. For example, in your personal machine, you could install opam from the install.sh script, place its root in your home folder, create two switches with some packages and configure VSCode with the following playbook :

- hosts: localhost
  roles:
    - role: opam-ansible
      vars:
        opam_install_method: direct
        opam_install_location: user
        configure_vscode: true
        opam_switches:
          - name: "default"
            compiler: "4.14.2"
            packages:
              - dune
              - tuareg
              - ocaml-lsp-server
          - name: "bleeding-edge"
            compiler: "5.2.0"
            packages:
              - dune
              - ocaml-lsp-server

In a CS lab, maybe you want to install opam using the package manager and put the root folder in a system-wide location that is available read-only to unprivileged users like this :

- hosts: localhost
  roles:
    - role: opam-ansible
      vars:
        opam_install_method: package_manager
        opam_install_location: system_wide
        opam_switches:
          - name: "default"
            compiler: "4.14.2"
            packages:
              - dune
              - tuareg
              - ocaml-lsp-server
          - name: "bleeding-edge"
            compiler: "5.2.0"
            packages:
              - dune
              - ocaml-lsp-server
              - qcheck

Here it is !

https://galaxy.ansible.com/ui/standalone/roles/plescornet/opam-ansible/documentation/

4 Likes