Skip to content

Instantly share code, notes, and snippets.

@rosmo
Last active January 19, 2022 09:35
Show Gist options
  • Save rosmo/d7b09252db7814ff52b24f0e907b33ea to your computer and use it in GitHub Desktop.
Save rosmo/d7b09252db7814ff52b24f0e907b33ea to your computer and use it in GitHub Desktop.
Install Cloud Ops Logging agent in a VM
[Service]
Environment=GOOGLE_SERVICE_CREDENTIALS=/etc/google/auth/application_default_credentials.json
ExecStartPre=/bin/sed -i "s/gce_instance/generic_node\\n location europe-west3\\n namespace example\\n node_id host.example.com/g" ${RUNTIME_DIRECTORY}/fluent_bit_main.conf
- name: Download Cloud Ops agent repo
get_url:
url: https://dl.google.com/cloudagents/add-google-cloud-ops-agent-repo.sh
dest: /tmp/add-google-cloud-ops-agent-repo.sh
mode: '0440'
when: not "/etc/yum.repos.d/google-cloud-ops-agent.repo" is exists
- name: Install Cloud Ops agent repo
shell: bash /tmp/add-google-cloud-ops-agent-repo.sh
when: not "/etc/yum.repos.d/google-cloud-ops-agent.repo" is exists
- name: Install Cloud Ops agent
yum:
name:
- google-cloud-ops-agent
state: present
- name: Create /etc/google/auth/ directory
ansible.builtin.file:
path: /etc/google/auth/
state: directory
mode: '0770'
- name: Install Google Cloud credentials
copy:
content: "{{ logging_credentials }}" # Service account key JSON contents
dest: /etc/google/auth/application_default_credentials.json
mode: '0770'
- name: Add credentials to environment for logging
ansible.builtin.template:
src: credentials.conf.j2
dest: /usr/lib/systemd/system/google-cloud-ops-agent-fluent-bit.service.d/credentials.conf
owner: root
group: root
mode: '0644'
- name: Add credentials to environment for metrics
ansible.builtin.template:
src: opentelemetry.conf.j2
dest: /usr/lib/systemd/system/google-cloud-ops-agent-opentelemetry-collector.service.d/credentials.conf
owner: root
group: root
mode: '0644'
- name: Start Cloud Ops agent service
ansible.builtin.systemd:
name: google-cloud-ops-agent
state: restarted
enabled: yes
daemon_reload: yes
#[Service]
#Environment=GOOGLE_APPLICATION_CREDENTIALS=/etc/google/auth/application_default_credentials.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment