Ansible playbook to install the RobotPKG APT repository

Besides installing the keyring and repository, this will also add the RobotPKG directories to the global PATH and LD_LIBRARY_PATH environment variables.

---
- name: Install RobotPKG Repository
  hosts: all
  become: yes
  tasks:
    - name: Install required packages
      apt:
        name: 
          - lsb-release
          - curl
        state: present
      register: apt_packages_installed

    - name: Create keyrings directory
      file:
        path: /usr/share/keyrings
        state: directory
        mode: '0755'

    - name: Download and add RobotPKG GPG key
      ansible.builtin.get_url:
        url: http://robotpkg.openrobots.org/packages/debian/robotpkg.asc
        dest: /usr/share/keyrings/robotpkg.asc
        mode: '0644'
    
    - name: Add RobotPKG repository
      apt_repository:
        repo: "deb [arch=amd64 signed-by=/usr/share/keyrings/robotpkg.asc] http://robotpkg.openrobots.org/packages/debian/pub {{ ansible_distribution_release }} robotpkg"
        state: present
        filename: robotpkg
      register: robotpkg_repo_added

    - name: Add robotpkg to PATH
      lineinfile:
        path: /etc/profile.d/99-robotpkg.sh
        create: yes
        line: "export PATH=/opt/openrobots/bin:$PATH"
        state: present

    - name: Add robotpkg to LD_LIBRARY_PATH
      lineinfile:
        path: /etc/profile.d/99-robotpkg.sh
        create: yes
        line: "export LD_LIBRARY_PATH=/opt/openrobots/lib:$LD_LIBRARY_PATH"
        state: present

    - name: Update apt cache
      apt:
        update_cache: yes
      when: >
        apt_packages_installed.changed or
        robotpkg_repo_added.changed