9 Commits
1.0.0 ... main

22 changed files with 334 additions and 27 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
/.idea /.idea
/.tox

33
.yamllint Normal file
View File

@@ -0,0 +1,33 @@
---
# Based on ansible-lint config
extends: default
rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable

20
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,20 @@
pipeline {
agent any
stages {
stage('checkout') {
steps {
echo 'Hello World'
git credentialsId: '6659caf8-95a2-4201-b6e0-bfe65e71836d',
url: 'git@github.com:Dannecron/netology-devops-ansible-vector.git',
branch: 'main'
}
}
stage('test') {
steps {
echo 'Run molecule test'
sh 'molecule test'
}
}
}
}

View File

@@ -1,4 +1,4 @@
ansible-vector netology-devops-ansible-vector
========= =========
Данная роль устанавливает `vector`. Данная роль устанавливает `vector`.

View File

@@ -3,4 +3,24 @@ vector_version: 0.23.0
vector_config_dir: /var/lib/vector vector_config_dir: /var/lib/vector
vector_config: vector_config:
data_dir: "{{ vector_config_dir }}" data_dir: "{{ vector_config_dir }}"
# todo добавить конфигурацию https://vector.dev/docs/reference/configuration/ sources:
file_logs:
type: file
acknowledgements: null
ignore_older_secs: 600
include:
- /var/log/**/*.log
read_from: beginning
sinks:
clickhouse:
type: clickhouse
inputs:
- file_logs
database: mydatabase
endpoint: http://localhost:8123
table: mytable
acknowledgements: null
compression: gzip
encoding: null
healthcheck: null
skip_unknown_fields: null

View File

@@ -1 +1,8 @@
--- ---
- name: Restart vector service
become: true
ansible.builtin.service:
name: vector
state: started
daemon_reload: true
listen: restart-vector

View File

@@ -1,5 +1,6 @@
galaxy_info: galaxy_info:
author: dannc author: dannc
role_name: netology_devops_vector
description: install vector description: install vector
company: "" company: ""
license: BSD-3-Clause license: BSD-3-Clause

View File

@@ -0,0 +1,38 @@
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y apt-transport-https gnupg2 python3-minimal python3-apt man systemd systemd-sysv rsyslog sudo bash ca-certificates iproute2 && apt-get clean; \
elif [ $(command -v yum) ]; then sed -i 's/^\(tsflags=*\)/# \1/g' /etc/yum.conf && yum makecache fast && yum upgrade -y && yum makecache fast && yum install -y sudo python3 systemd rsyslog man yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; fi
RUN set -xe \
&& groupadd -r ${ANSIBLE_USER} \
&& groupadd -r ${DEPLOY_GROUP} \
&& useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \
&& usermod -aG ${DEPLOY_GROUP} ${ANSIBLE_USER} \
&& echo "%${DEPLOY_GROUP} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ansible
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -rf /lib/systemd/system/multi-user.target.wants/*;\
rm -rf /etc/systemd/system/*.wants/*;\
rm -rf /lib/systemd/system/local-fs.target.wants/*; \
rm -rf /lib/systemd/system/sockets.target.wants/*udev*; \
rm -rf /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -rf /lib/systemd/system/basic.target.wants/*;\
rm -rf /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["{{ item.command | default('/usr/sbin/init') }}"]

View File

@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include netology_devops_vector"
ansible.builtin.include_role:
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"

View File

@@ -0,0 +1,62 @@
---
dependency:
name: galaxy
driver:
name: docker
lint: |
yamllint .
ansible-lint
platforms:
- name: centos_7
image: centos:7
privileged: true
command: /usr/sbin/init
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
env:
ANSIBLE_USER: ansible
SUDO_GROUP: wheel
DEPLOY_GROUP: deployer
container: docker
- name: debian_bullseye_11
image: debian:bullseye
privileged: true
command: /sbin/init
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
env:
ANSIBLE_USER: ansible
SUDO_GROUP: sudo
DEPLOY_GROUP: deployer
container: docker
provisioner:
name: ansible
verifier:
name: ansible
scenario:
name: default
test_sequence:
- lint
- destroy
# - dependency
- syntax
- create
# - prepare
- converge
- idempotence
# - side_effect
- verify
- destroy

View File

@@ -0,0 +1,9 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Ensure vector service started
ansible.builtin.service:
name: vector
state: started

View File

@@ -0,0 +1,38 @@
{% if item.registry is defined %}
FROM {{ item.registry.url }}/{{ item.image }}
{% else %}
FROM {{ item.image }}
{% endif %}
{% if item.env is defined %}
{% for var, value in item.env.items() %}
{% if value %}
ENV {{ var }} {{ value }}
{% endif %}
{% endfor %}
{% endif %}
RUN if [ $(command -v apt-get) ]; then apt-get update && apt-get upgrade -y && apt-get install -y apt-transport-https gnupg2 python3-minimal python3-apt man systemd systemd-sysv rsyslog sudo bash ca-certificates iproute2 && apt-get clean; \
elif [ $(command -v yum) ]; then sed -i 's/^\(tsflags=*\)/# \1/g' /etc/yum.conf && yum makecache fast && yum upgrade -y && yum makecache fast && yum install -y sudo python3 systemd rsyslog man yum-plugin-ovl bash iproute && sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf && yum clean all; fi
RUN set -xe \
&& groupadd -r ${ANSIBLE_USER} \
&& groupadd -r ${DEPLOY_GROUP} \
&& useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \
&& usermod -aG ${DEPLOY_GROUP} ${ANSIBLE_USER} \
&& echo "%${DEPLOY_GROUP} ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/ansible
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == \
systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -rf /lib/systemd/system/multi-user.target.wants/*;\
rm -rf /etc/systemd/system/*.wants/*;\
rm -rf /lib/systemd/system/local-fs.target.wants/*; \
rm -rf /lib/systemd/system/sockets.target.wants/*udev*; \
rm -rf /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -rf /lib/systemd/system/basic.target.wants/*;\
rm -rf /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["{{ item.command | default('/usr/sbin/init') }}"]

View File

@@ -0,0 +1,7 @@
---
- name: Converge
hosts: all
tasks:
- name: "Include netology_devops_vector"
ansible.builtin.include_role:
name: "{{ lookup('env', 'MOLECULE_PROJECT_DIRECTORY') | basename }}"

View File

@@ -0,0 +1,35 @@
---
dependency:
name: galaxy
driver:
name: podman
platforms:
- name: centos_7
image: docker.io/library/centos:7
privileged: true
command: /usr/sbin/init
capabilities:
- SYS_ADMIN
tmpfs:
- /run
- /tmp
volumes:
- /sys/fs/cgroup:/sys/fs/cgroup
env:
ANSIBLE_USER: ansible
SUDO_GROUP: wheel
DEPLOY_GROUP: deployer
container: podman
provisioner:
name: ansible
verifier:
name: ansible
scenario:
name: podman
test_sequence:
- lint
- destroy
- create
- converge
- verify
- destroy

View File

@@ -0,0 +1,9 @@
---
- name: Verify
hosts: all
gather_facts: false
tasks:
- name: Ensure vector service started
ansible.builtin.service:
name: vector
state: started

View File

@@ -1,27 +1,25 @@
--- ---
- name: vector | install archive manager - name: Vector | install archive manager
become: true ansible.builtin.include_tasks:
ansible.builtin.yum: file: "pre_install/{{ ansible_pkg_mgr }}.yml"
name: - name: Vector | get distrib
- tar
- name: vector | get distrib
ansible.builtin.get_url: ansible.builtin.get_url:
url: "https://packages.timber.io/vector/{{ vector_version }}/vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz" url: "https://packages.timber.io/vector/{{ vector_version }}/vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz"
dest: "./vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz" dest: "./vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz"
mode: "755" mode: "755"
- name: vector | unpack distrib - name: Vector | unpack distrib
ansible.builtin.unarchive: ansible.builtin.unarchive:
src: "./vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz" src: "./vector-{{ vector_version }}-x86_64-unknown-linux-musl.tar.gz"
dest: "./" dest: "./"
remote_src: true remote_src: true
- name: vector | install - name: Vector | install
become: true become: true
ansible.builtin.copy: ansible.builtin.copy:
src: "vector-x86_64-unknown-linux-musl/bin/vector" src: "vector-x86_64-unknown-linux-musl/bin/vector"
dest: "/usr/local/bin/" dest: "/usr/local/bin/"
remote_src: true remote_src: true
mode: "755" mode: "755"
- name: vector | check installed version - name: Vector | check installed version
ansible.builtin.command: ansible.builtin.command:
cmd: vector --version cmd: vector --version
register: result register: result
@@ -29,7 +27,7 @@
- 'vector_version not in result.stdout' - 'vector_version not in result.stdout'
tags: tags:
- vector_check_version - vector_check_version
- name: vector | create data dir - name: Vector | create data dir
become: true become: true
ansible.builtin.file: ansible.builtin.file:
mode: "755" mode: "755"
@@ -37,12 +35,12 @@
group: "{{ ansible_effective_group_id }}" group: "{{ ansible_effective_group_id }}"
path: "{{ vector_config_dir }}" path: "{{ vector_config_dir }}"
state: "directory" state: "directory"
- name: vector | template config - name: Vector | template config
ansible.builtin.template: ansible.builtin.template:
src: "templates/vector.config.j2" src: "templates/vector.config.j2"
dest: "{{ vector_config_dir }}/vector.yaml" dest: "{{ vector_config_dir }}/vector.yaml"
mode: "755" mode: "755"
- name: vector | register as service - name: Vector | register as service
become: true become: true
ansible.builtin.template: ansible.builtin.template:
src: "templates/vector.service.j2" src: "templates/vector.service.j2"
@@ -51,9 +49,5 @@
group: "{{ ansible_effective_group_id }}" group: "{{ ansible_effective_group_id }}"
mode: "0644" mode: "0644"
backup: true backup: true
- name: vector | start service notify:
become: true - restart-vector
ansible.builtin.service:
name: vector
state: started
daemon_reload: true

View File

@@ -0,0 +1,6 @@
---
- name: Vector | install archive manager
become: true
ansible.builtin.apt:
name:
- tar

View File

@@ -0,0 +1,6 @@
---
- name: Vector | install archive manager
become: true
ansible.builtin.yum:
name:
- tar

View File

@@ -1,2 +0,0 @@
localhost

View File

@@ -1,5 +0,0 @@
---
- hosts: localhost
remote_user: root
roles:
- vector-role

7
tox-requirements.txt Normal file
View File

@@ -0,0 +1,7 @@
selinux
ansible-lint==5.1.3
yamllint==1.26.3
lxml
molecule==3.4.0
molecule_podman
jmespath

14
tox.ini Normal file
View File

@@ -0,0 +1,14 @@
[tox]
minversion = 1.8
basepython = python3.6
envlist = py{37,39}-ansible{210,30}
skipsdist = true
[testenv]
passenv = *
deps =
-r tox-requirements.txt
ansible210: ansible<3.0
ansible30: ansible<3.1
commands =
{posargs:molecule test -s podman}