--- - name: Create Promtail directories file: path: "{{ item }}" state: directory mode: '0755' loop: - "{{ promtail_config_dir }}" - "{{ promtail_data_dir }}" become: yes - name: Set proper permissions for Promtail data directory file: path: "{{ promtail_data_dir }}" state: directory owner: promtail group: promtail mode: '0755' recurse: yes become: yes - name: Create positions file with correct permissions file: path: "{{ promtail_data_dir }}/positions.yaml" state: touch owner: promtail group: promtail mode: '0644' become: yes - name: Add promtail user to adm group for system log access user: name: promtail groups: adm append: yes become: yes - name: Download Promtail binary get_url: url: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/promtail-linux-amd64.zip" dest: /tmp/promtail-linux-amd64.zip mode: '0644' timeout: 60 become: yes - name: Install Promtail binary unarchive: src: /tmp/promtail-linux-amd64.zip dest: /usr/local/bin/ remote_src: yes owner: root group: root mode: '0755' become: yes - name: Create Promtail system user user: name: promtail system: yes shell: /usr/sbin/nologin create_home: no become: yes - name: Deploy Promtail configuration template: src: promtail-config.yml.j2 dest: "{{ promtail_config_dir }}/promtail-config.yml" mode: '0644' notify: restart promtail become: yes - name: Deploy Promtail systemd service (as root) copy: content: | [Unit] Description=Promtail log collector Documentation=https://grafana.com/docs/loki/latest/clients/promtail/ Wants=network-online.target After=network-online.target [Service] Type=simple User=root Group=root ExecStart=/usr/local/bin/promtail-linux-amd64 \ -config.file={{ promtail_config_dir }}/promtail-config.yml ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure RestartSec=5s [Install] WantedBy=multi-user.target dest: /etc/systemd/system/promtail.service mode: '0644' notify: restart promtail become: yes - name: Start and enable Promtail service systemd: name: promtail state: started enabled: yes daemon_reload: yes become: yes - name: Clean up temporary files file: path: /tmp/promtail-linux-amd64.zip state: absent become: yes