--- - name: User | Create the daemon group ansible.builtin.group: name: "{{ multica_group }}" state: present become: true when: multica_manage_user | bool # Deliberately not a system account: the daemon needs a real home for CLI # config and agent CLI credentials, and systemd linger needs a real user. - name: User | Create the daemon user ansible.builtin.user: name: "{{ multica_user }}" group: "{{ multica_group }}" groups: "{{ multica_user_extra_groups }}" append: true home: "{{ multica_user_home }}" shell: "{{ multica_user_shell }}" create_home: true state: present become: true when: multica_manage_user | bool - name: User | Look up the daemon user ansible.builtin.getent: database: passwd key: "{{ multica_user }}" become: true - name: User | Record uid and the per-user runtime environment ansible.builtin.set_fact: _multica_uid: "{{ ansible_facts.getent_passwd[multica_user][1] }}" # systemd user units — which is what `multica daemon autostart enable` writes on # Linux — are unreachable over a plain `sudo -u` shell without these. Without # XDG_RUNTIME_DIR, `systemctl --user` fails with "Failed to connect to bus". - name: User | Build the daemon user's command environment ansible.builtin.set_fact: _multica_user_env: HOME: "{{ multica_user_home }}" USER: "{{ multica_user }}" LOGNAME: "{{ multica_user }}" XDG_RUNTIME_DIR: "/run/user/{{ _multica_uid }}" DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/{{ _multica_uid }}/bus" PATH: "{{ multica_npm_prefix }}/bin:{{ multica_user_home }}/.local/bin:{{ multica_install_dir }}:/usr/local/bin:/usr/bin:/bin" - name: User | Ensure the user's local bin directory exists ansible.builtin.file: path: "{{ multica_user_home }}/.local/bin" state: directory owner: "{{ multica_user }}" group: "{{ multica_group }}" mode: "0755" become: true - name: User | Ensure the user's cache directory exists ansible.builtin.file: path: "{{ multica_user_home }}/.cache" state: directory owner: "{{ multica_user }}" group: "{{ multica_group }}" mode: "0700" become: true