This commit is contained in:
Илья Макаров 2025-02-21 12:19:22 +03:00
parent 70f0eca45a
commit 216da45c80
24 changed files with 580 additions and 0 deletions

6
playbooks/fail2ban.yml Normal file

@ -0,0 +1,6 @@
---
- name: Ensure fail2ban is installed and configured
hosts: srv_1
roles:
- ../roles/fail2ban

@ -0,0 +1,8 @@
---
- name: Установка oh-my-posh
hosts: srv_1
vars_files:
- ../roles/ohmyposh_theme/vault.yml
roles:
- ohmyposh_theme

38
roles/fail2ban/README.md Normal file

@ -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).

@ -0,0 +1,7 @@
---
# defaults file for fail2ban
fail2ban_bantime: -1
fail2ban_findtime: 86400
fail2ban_maxretry: 3
ssh_port: 10001

@ -0,0 +1,6 @@
---
- name: Restart fail2ban
ansible.builtin.service:
name: fail2ban
state: restarted

@ -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.

@ -0,0 +1,32 @@
- name: Install Fail2Ban package
ansible.builtin.package:
name: fail2ban
state: present
- name: Ensure Fail2Ban service file exists
ansible.builtin.stat:
path: /usr/lib/systemd/system/fail2ban.service
register: fail2ban_service
- name: Debug
debug:
var: fail2ban_service
- name: Deploy jail.local configuration
ansible.builtin.template:
src: jail.local.j2
dest: /etc/fail2ban/jail.local
owner: root
group: root
mode: '0644'
when: fail2ban_service.stat.exists
notify: Restart fail2ban
- name: Enable and start Fail2Ban service
ansible.builtin.service:
name: fail2ban
state: started
enabled: yes
when: fail2ban_service.stat.exists

@ -0,0 +1,23 @@
---
# tasks file for fail2ban
- name: Install Fail2Ban package
ansible.builtin.package:
name: fail2ban
state: present
- name: Deploy jail.local configuration
ansible.builtin.template:
src: jail.local.j2
dest: /etc/fail2ban/jail.local
owner: root
group: root
mode: '0644'
notify: Restart fail2ban
- name: Enable and start Fail2Ban service
ansible.builtin.service:
name: fail2ban
state: started
enabled: yes

@ -0,0 +1,10 @@
[sshd]
bantime = {{ fail2ban_bantime }}
findtime = {{ fail2ban_findtime }}
maxretry = {{ fail2ban_maxretry }}
enabled = true
port = {{ ssh_port }}
filter = sshd
logpath = /var/log/auth.log
maxretry = 3

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

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

@ -0,0 +1,2 @@
---
# vars file for fail2ban

@ -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).

@ -0,0 +1,9 @@
---
# defaults file for ohmyposh_theme
oh_my_posh_version: "v24.19.0"
oh_my_posh_download_url: "https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/{{ oh_my_posh_version }}/posh-linux-amd64"
theme_file: "amro.omp.json"
theme_path: "/home/{{ user_for_ohmyposh }}/.poshthemes/{{ theme_file }}"
nerd_fonts_url: "https://github.com/ryanoasis/nerd-fonts/releases/download/v3.3.0/0xProto.zip"
user_for_ohmyposh: "ilyamak04"

@ -0,0 +1,58 @@
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "#45F1C2",
"style": "plain",
"template": "\ueb99 {{ .UserName }} on",
"type": "session"
},
{
"foreground": "#0CA0D8",
"properties": {
"folder_separator_icon": "/",
"style": "full"
},
"style": "plain",
"template": " \uf07b {{ .Path }} ",
"type": "path"
},
{
"foreground": "#14A5AE",
"powerline_symbol": "\ue0b0",
"properties": {
"fetch_stash_count": true,
"fetch_upstream_icon": true
},
"style": "plain",
"template": "{{ .UpstreamIcon }}{{ .HEAD }}{{ if gt .StashCount 0 }} \ueb4b {{ .StashCount }}{{ end }} ",
"type": "git"
}
],
"type": "prompt"
},
{
"alignment": "left",
"newline": true,
"segments": [
{
"foreground": "#cd5e42",
"style": "plain",
"template": "\ue3bf ",
"type": "root"
},
{
"foreground": "#CD4277",
"style": "plain",
"template": "# ",
"type": "text"
}
],
"type": "prompt"
}
],
"version": 3
}

@ -0,0 +1,68 @@
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"palette": {
"os": "#ACB0BE",
"closer": "p:os",
"pink": "#ea76cb",
"lavender": "#7287FD",
"blue": "#1e66f5"
},
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "p:os",
"style": "plain",
"template": "{{.Icon}} ",
"type": "os"
},
{
"foreground": "p:blue",
"style": "plain",
"template": "{{ .UserName }}@{{ .HostName }} ",
"type": "session"
},
{
"foreground": "p:pink",
"properties": {
"folder_icon": "..\ue5fe..",
"home_icon": "~",
"style": "agnoster_short"
},
"style": "plain",
"template": "{{ .Path }} ",
"type": "path"
},
{
"foreground": "p:lavender",
"properties": {
"branch_icon": "\ue725 ",
"cherry_pick_icon": "\ue29b ",
"commit_icon": "\uf417 ",
"fetch_status": false,
"fetch_upstream_icon": false,
"merge_icon": "\ue727 ",
"no_commits_icon": "\uf0c3 ",
"rebase_icon": "\ue728 ",
"revert_icon": "\uf0e2 ",
"tag_icon": "\uf412 "
},
"template": "{{ .HEAD }} ",
"style": "plain",
"type": "git"
},
{
"style": "plain",
"foreground": "p:closer",
"template": "\uf105",
"type": "text"
}
],
"type": "prompt"
}
],
"final_space": true,
"version": 3
}

@ -0,0 +1,67 @@
{
"$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
"palette": {
"os": "#ACB0BE",
"closer": "p:os",
"pink": "#F5BDE6",
"lavender": "#B7BDF8",
"blue": "#8AADF4"
},
"blocks": [
{
"alignment": "left",
"segments": [
{
"foreground": "p:os",
"style": "plain",
"template": "{{.Icon}} ",
"type": "os"
},
{
"foreground": "p:blue",
"style": "plain",
"template": "{{ .UserName }}@{{ .HostName }} ",
"type": "session"
},
{
"foreground": "p:pink",
"properties": {
"folder_icon": "..\ue5fe..",
"home_icon": "~",
"style": "agnoster_short"
},
"style": "plain",
"template": "{{ .Path }} ",
"type": "path"
},
{
"foreground": "p:lavender",
"properties": {
"branch_icon": "\ue725 ",
"cherry_pick_icon": "\ue29b ",
"commit_icon": "\uf417 ",
"fetch_status": false,
"fetch_upstream_icon": false,
"merge_icon": "\ue727 ",
"no_commits_icon": "\uf0c3 ",
"rebase_icon": "\ue728 ",
"revert_icon": "\uf0e2 ",
"tag_icon": "\uf412 "
},
"template": "{{ .HEAD }} ",
"style": "plain",
"type": "git"
},
{
"style": "plain",
"foreground": "p:closer",
"template": "\uf105",
"type": "text"
}
],
"type": "prompt"
}
],
"final_space": true,
"version": 3
}

@ -0,0 +1,2 @@
---
# handlers file for ohmyposh_theme

@ -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.

@ -0,0 +1,76 @@
---
# tasks file for ohmyposh_theme
- name: Загружаем oh-my-posh
get_url:
url: "{{ oh_my_posh_download_url }}"
dest: /home/{{ user_for_ohmyposh }}/oh-my-posh
mode: '0755'
- name: Перемещаем oh-my-posh в /usr/local/bin
command: mv "/home/{{ user_for_ohmyposh }}/oh-my-posh" /usr/local/bin/oh-my-posh
- name: Создание директории для тем
file:
path: "/home/{{ user_for_ohmyposh }}/.poshthemes"
state: directory
owner: "{{ user_for_ohmyposh }}"
group: "{{ user_for_ohmyposh }}"
mode: "0755"
- name: Копирование темы в директорию
copy:
src: "{{ theme_file }}"
dest: "{{ theme_path }}"
owner: "{{ user_for_ohmyposh }}"
group: "{{ user_for_ohmyposh }}"
mode: "0644"
- name: Обновить .bashrc для инициализации oh-my-posh
lineinfile:
path: "/home/{{ user_for_ohmyposh }}/.bashrc"
line: 'eval "$(oh-my-posh --init --shell bash --config {{ theme_path }})"'
state: present
- name: Загрузить и установить Nerd Fonts
block:
- name: Создаем директорию для шрифтов
file:
path: "/home/{{ user_for_ohmyposh }}/.local/share/fonts"
state: directory
owner: "{{ user_for_ohmyposh }}"
group: "{{ user_for_ohmyposh }}"
mode: "755"
register: fonts_dir
- name: ll
command: "ls -la /home/{{ user_for_ohmyposh }}/.local"
register: ll
- debug:
var: ll.stdout
- debug:
var: fonts_dir
- name: Загружаем архив с шрифтами
get_url:
url: "{{ nerd_fonts_url }}"
dest: "/home/{{ user_for_ohmyposh }}/.local/share/fonts/0xProto.zip"
owner: "{{ user_for_ohmyposh }}"
group: "{{ user_for_ohmyposh }}"
mode: "0644"
- name: Распаковываем шрифты
unarchive:
src: "/home/{{ user_for_ohmyposh }}/.local/share/fonts/0xProto.zip"
dest: "/home/{{ user_for_ohmyposh }}/.local/share/fonts/"
remote_src: yes
- name: Обновляем кэш шрифтов
command: fc-cache -fv
changed_when: false
- name: Применяем изменения в .bashrc
command: source "/home/{{ user_for_ohmyposh }}/.bashrc"
changed_when: false

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

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

@ -0,0 +1,5 @@
---
# vars file for ohmyposh_theme
ansible_become_user: "{{ user_for_ohmyposh }}"
ansible_become_password: "{{ vault_become_password }}"

@ -0,0 +1,7 @@
$ANSIBLE_VAULT;1.1;AES256
39626634313932323532313431343135636464353930346334646534643861356662316265383731
3962393535616237653537373935623066626265616461350a373164643430383665313939666264
34656237626366633832323436313066663461376462343531626265383164333735653565356362
3533393866373635660a353032646130663461373565633531633266363266383161353661336561
66323037623737346437313931373862323564633232336130383962643139643963343265386561
3263623465363738396439623263666161386266623965613038