-
Notifications
You must be signed in to change notification settings - Fork 0
Nida #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Nida #2
Changes from 6 commits
c185146
6737ea8
604af27
472b75d
aa77a26
73cc0ef
ea13dbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
[defaults] | ||
inventory = aws_ec2.yml # Path to your inventory file | ||
host_key_checking = False # Optional: disable host key checking for SSH | ||
remote_user = ubuntu # Default user for SSH connections | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to degine the remote_user as |
||
private_key_file = /home/fateh/Downloads/westkey.pem | ||
|
||
[inventory] | ||
enable_plugins = aws_ec2 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
plugin: aws_ec2 | ||
regions: | ||
- us-west-1 | ||
filters: | ||
"tag:Name": "loki" | ||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also add tags for promtails so that we can install promtail agent on all VMs where every required |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. update the README.md |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
Role Name | ||
========= | ||
|
||
A brief description of the role goes here. | ||
|
||
Requirements | ||
------------ | ||
|
||
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. | ||
|
||
Role Variables | ||
-------------- | ||
|
||
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. | ||
|
||
Dependencies | ||
------------ | ||
|
||
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. | ||
|
||
Example Playbook | ||
---------------- | ||
|
||
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: | ||
|
||
- hosts: servers | ||
roles: | ||
- { role: username.rolename, x: 42 } | ||
|
||
License | ||
------- | ||
|
||
BSD | ||
|
||
Author Information | ||
------------------ | ||
|
||
An optional section for the role authors to include contact information, or a website (HTML is not allowed). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--- | ||
# defaults file for loki_role |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
auth_enabled: false | ||
|
||
server: | ||
http_listen_port: 3100 | ||
|
||
ingester: | ||
lifecycler: | ||
address: 127.0.0.1 | ||
ring: | ||
kvstore: | ||
store: inmemory | ||
replication_factor: 1 | ||
final_sleep: 0s | ||
chunk_idle_period: 5m | ||
chunk_retain_period: 30s | ||
max_transfer_retries: 0 | ||
|
||
schema_config: | ||
configs: | ||
- from: 2018-04-15 | ||
store: boltdb | ||
object_store: filesystem | ||
schema: v11 | ||
index: | ||
prefix: index_ | ||
period: 168h | ||
|
||
storage_config: | ||
boltdb: | ||
directory: /data/loki/index | ||
|
||
filesystem: | ||
directory: /data/loki/chunks | ||
|
||
limits_config: | ||
enforce_metric_name: false | ||
reject_old_samples: true | ||
reject_old_samples_max_age: 168h | ||
|
||
chunk_store_config: | ||
max_look_back_period: 0s | ||
|
||
table_manager: | ||
retention_deletes_enabled: false | ||
retention_period: 0s |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Loki service | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
User=root | ||
Restart=on-failure | ||
ExecStart=/usr/local/bin/loki -config.file /etc/loki/loki-local-config.yaml | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
server: | ||
http_listen_port: 9080 | ||
grpc_listen_port: 0 | ||
|
||
positions: | ||
filename: /data/loki/positions.yaml | ||
|
||
clients: | ||
- url: http://localhost:3100/loki/api/v1/push | ||
|
||
scrape_configs: | ||
- job_name: system | ||
static_configs: | ||
- targets: | ||
- localhost | ||
labels: | ||
job: varlogs | ||
__path__: /var/log/*log |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=Promtail service | ||
After=network.target | ||
|
||
[Service] | ||
Type=simple | ||
User=root | ||
ExecStart=/usr/local/bin/promtail -config.file /etc/promtail-local-config.yaml | ||
Restart=on-failure | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
--- | ||
# handlers file for loki_rol | ||
- name: Restart loki | ||
ansible.builtin.service: | ||
name: loki | ||
state: started | ||
enabled: true | ||
|
||
- name: starting grafana | ||
ansible.builtin.systemd: | ||
name: grafana-server | ||
state: started | ||
enabled: true | ||
|
||
- name: start promtail | ||
ansible.builtin.systemd: | ||
name: promtail | ||
state: started | ||
enabled: true | ||
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if meta.yml is not required then delete it |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# galaxy_info: | ||
# author: your name | ||
# description: your role description | ||
# company: your company (optional) | ||
|
||
# If the issue tracker for your role is not on github, uncomment the | ||
# next line and provide a value | ||
# issue_tracker_url: http://example.com/issue/tracker | ||
|
||
# Choose a valid license ID from https://spdx.org - some suggested licenses: | ||
# - BSD-3-Clause (default) | ||
# - MIT | ||
# - GPL-2.0-or-later | ||
# - GPL-3.0-only | ||
# - Apache-2.0 | ||
# - CC-BY-4.0 | ||
# license: license (GPL-2.0-or-later, MIT, etc) | ||
|
||
#min_ansible_version: 2.1 | ||
|
||
# If this a Container Enabled role, provide the minimum Ansible Container version. | ||
# min_ansible_container_version: | ||
|
||
# | ||
# Provide a list of supported platforms, and for each platform a list of versions. | ||
# If you don't wish to enumerate all versions for a particular platform, use 'all'. | ||
# To view available platforms and versions (or releases), visit: | ||
# https://galaxy.ansible.com/api/v1/platforms/ | ||
# | ||
# platforms: | ||
# - name: Fedora | ||
# versions: | ||
# - all | ||
# - 25 | ||
# - name: SomePlatform | ||
# versions: | ||
# - all | ||
# - 1.0 | ||
# # - 7 | ||
# # - 99.99 | ||
|
||
# galaxy_tags: [] | ||
# # List tags for your role here, one per line. A tag is a keyword that describes | ||
# # and categorizes the role. Users find roles by searching for tags. Be sure to | ||
# # remove the '[]' above, if you add tags to this list. | ||
# # | ||
# # NOTE: A tag is limited to a single word comprised of alphanumeric characters. | ||
# # Maximum 20 tags per role. | ||
|
||
# dependencies: [] | ||
# # List your role dependencies here, one per line. Be sure to remove the '[]' above, | ||
# # if you add dependencies to this list. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
- name: Install prerequisite packages on Debian-based systems | ||
ansible.builtin.apt: | ||
name: | ||
- gnupg | ||
- curl | ||
state: present | ||
when: ansible_facts['os_family'] == 'Debian' | ||
Comment on lines
+2
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As we discussed earlier as well variables the package name don't hardcode it inside the role |
||
|
||
- name: Add Grafana GPG key on Debian-based systems | ||
ansible.builtin.apt_key: | ||
url: https://packages.grafana.com/gpg.key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this url should be also be variablised |
||
state: present | ||
when: ansible_facts['os_family'] == 'Debian' | ||
|
||
- name: Add Grafana repository on Debian-based systems | ||
ansible.builtin.apt_repository: | ||
repo: "deb https://packages.grafana.com/oss/deb stable main" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also need to variables |
||
state: present | ||
when: ansible_facts['os_family'] == 'Debian' | ||
|
||
- name: Update apt package repository on Debian-based systems | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't we do update cache and install grafana in single. Command I think it is achievable please look into this |
||
ansible.builtin.apt: | ||
update_cache: yes | ||
when: ansible_facts['os_family'] == 'Debian' | ||
|
||
- name: Install Grafana on Debian-based systems | ||
ansible.builtin.apt: | ||
name: grafana | ||
state: present | ||
when: ansible_facts['os_family'] == 'Debian' | ||
notify: starting grafana | ||
|
||
- name: Install prerequisite packages on Red Hat-based systems | ||
ansible.builtin.yum: | ||
name: | ||
- gnupg | ||
- curl | ||
state: present | ||
when: ansible_facts['os_family'] == 'RedHat' | ||
Comment on lines
+34
to
+40
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variables the package name inside the vars.yml shouldn't be hardcoded |
||
|
||
- name: Add Grafana GPG key on Red Hat-based systems | ||
ansible.builtin.rpm_key: | ||
state: present | ||
key: https://packages.grafana.com/gpg.key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make this as a variable |
||
when: ansible_facts['os_family'] == 'RedHat' | ||
|
||
- name: Add Grafana repository on Red Hat-based systems | ||
ansible.builtin.yum_repository: | ||
name: grafana | ||
description: Grafana OSS Repository | ||
baseurl: https://packages.grafana.com/oss/rpm | ||
gpgcheck: 1 | ||
gpgkey: https://packages.grafana.com/gpg.key | ||
enabled: 1 | ||
when: ansible_facts['os_family'] == 'RedHat' | ||
|
||
- name: Install Grafana on Red Hat-based systems | ||
ansible.builtin.yum: | ||
name: grafana | ||
state: present | ||
when: ansible_facts['os_family'] == 'RedHat' | ||
notify: starting grafana | ||
Comment on lines
+48
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. variabilize the package name nothing should be hard coded inside the tasks. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
--- | ||
- name: updating cache of ubuntu | ||
ansible.builtin.apt: | ||
update_cache: yes | ||
|
||
- name: Install unzip, bzip2, xz-utils, and zstd | ||
ansible.builtin.apt: | ||
name: | ||
- unzip | ||
- bzip2 | ||
- xz-utils | ||
- zstd | ||
state: present | ||
Comment on lines
+6
to
+13
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here not variabilized |
||
|
||
- name: Download Binaries for loki | ||
ansible.builtin.get_url: | ||
url: "https://github.com/grafana/loki/releases/download/v{{ loki_version }}/loki-linux-amd64.zip" | ||
dest: /home/ubuntu/ | ||
mode: '755' | ||
|
||
- name: Unarchive a file | ||
ansible.builtin.unarchive: | ||
src: "/home/ubuntu/loki-linux-amd64.zip" | ||
dest: /home/ubuntu/ | ||
remote_src: yes | ||
|
||
|
||
- name: Add the user 'loki' | ||
ansible.builtin.user: | ||
name: loki | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. username should also be variabilized |
||
state: present | ||
system: true | ||
|
||
- name: Copy file with owner and permissions | ||
ansible.builtin.copy: | ||
src: /home/ubuntu/loki-linux-amd64 | ||
dest: /usr/local/bin/loki | ||
owner: loki | ||
group: loki | ||
mode: '755' | ||
remote_src: true | ||
|
||
|
||
- name: Creating directory for config file | ||
ansible.builtin.file: | ||
path: "{{ item }}" | ||
state: directory | ||
owner: loki | ||
group: loki | ||
mode: '755' | ||
recurse: true | ||
loop: | ||
- /etc/loki/logs | ||
- /data/loki | ||
Comment on lines
+44
to
+54
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this directory path should also be define in vars.yml |
||
|
||
- name: Creating Config file | ||
ansible.builtin.file: | ||
path: /etc/loki/loki-local-config.yaml | ||
state: touch | ||
Comment on lines
+56
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file should also be not created as we are going to copy it from our ansible controller to slave. So doesn't requires to create it |
||
|
||
|
||
- name: Copying the config file content | ||
ansible.builtin.template: | ||
src: templates/loki-config.j2 | ||
dest: /etc/loki/loki-local-config.yaml | ||
Comment on lines
+62
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have we tested this if it is working fine or not. I think you haven't add values to jinja template till now directly copy pasting the jinja template. |
||
|
||
- name: Creating service file | ||
ansible.builtin.file: | ||
path: /etc/systemd/system/loki.service | ||
state: touch | ||
Comment on lines
+67
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here not required to create a file |
||
|
||
- name: Reload systemd manager configuration | ||
ansible.builtin.systemd: | ||
daemon_reload: true | ||
|
||
- name: Copying the system file content | ||
ansible.builtin.copy: | ||
src: files/loki-service | ||
dest: /etc/systemd/system/loki.service | ||
notify: Restart loki | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
|
||
|
||
- name: Include grafana tasks | ||
ansible.builtin.include_tasks: | ||
file: grafana.yaml | ||
when: run_grafana_tasks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change it to something like |
||
|
||
- name: Include Loki tasks | ||
ansible.builtin.include_tasks: | ||
file: loki.yaml | ||
when: run_loki_tasks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here refer to above comment |
||
|
||
|
||
- name: Include promtail tasks | ||
ansible.builtin.include_tasks: | ||
file: promtail.yml | ||
when: run_promtail_tasks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also add keygroups in dynamic inventory and make sure we make use of private IP to list the instance using dynamic inventory.