提交ansible自动部署

master
root 3 years ago
parent 15ee113c69
commit 1b17965d70
  1. 14
      zabbix-ansible/hosts
  2. 29
      zabbix-ansible/mariadb/.travis.yml
  3. 38
      zabbix-ansible/mariadb/README.md
  4. 2
      zabbix-ansible/mariadb/defaults/main.yml
  5. 5
      zabbix-ansible/mariadb/files/mariadb.repo
  6. 6
      zabbix-ansible/mariadb/files/my.cnf
  7. 4
      zabbix-ansible/mariadb/handlers/main.yml
  8. 53
      zabbix-ansible/mariadb/meta/main.yml
  9. 18
      zabbix-ansible/mariadb/tasks/main.yml
  10. 2
      zabbix-ansible/mariadb/tests/inventory
  11. 5
      zabbix-ansible/mariadb/tests/test.yml
  12. 2
      zabbix-ansible/mariadb/vars/main.yml
  13. 5
      zabbix-ansible/roles.yml
  14. 29
      zabbix-ansible/zabbix-agentd/.travis.yml
  15. 38
      zabbix-ansible/zabbix-agentd/README.md
  16. 2
      zabbix-ansible/zabbix-agentd/defaults/main.yml
  17. 2
      zabbix-ansible/zabbix-agentd/handlers/main.yml
  18. 53
      zabbix-ansible/zabbix-agentd/meta/main.yml
  19. 2
      zabbix-ansible/zabbix-agentd/tasks/main.yml
  20. 2
      zabbix-ansible/zabbix-agentd/tests/inventory
  21. 5
      zabbix-ansible/zabbix-agentd/tests/test.yml
  22. 2
      zabbix-ansible/zabbix-agentd/vars/main.yml
  23. 29
      zabbix-ansible/zabbix-server/.travis.yml
  24. 38
      zabbix-ansible/zabbix-server/README.md
  25. 2
      zabbix-ansible/zabbix-server/defaults/main.yml
  26. 75
      zabbix-ansible/zabbix-server/files/nginx.conf
  27. 5
      zabbix-ansible/zabbix-server/handlers/main.yml
  28. 53
      zabbix-ansible/zabbix-server/meta/main.yml
  29. 38
      zabbix-ansible/zabbix-server/tasks/main.yml
  30. 17
      zabbix-ansible/zabbix-server/templates/zabbix_server.conf.j2
  31. 2
      zabbix-ansible/zabbix-server/tests/inventory
  32. 5
      zabbix-ansible/zabbix-server/tests/test.yml
  33. 4
      zabbix-ansible/zabbix-server/vars/main.yml

@ -0,0 +1,14 @@
[server]
192.168.241.165
[database]
192.168.241.165
[zabbix-server:children]
server
database
[zabbix-server:vars]
dbUser=remote
dbPassword=123456
dbName=zabbix

@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

@ -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,2 @@
---
# defaults file for mariadb

@ -0,0 +1,5 @@
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.4/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

@ -0,0 +1,6 @@
[mysqld]
skip_name_resolve = ON #跳过主机名解析
innodb_file_per_table = ON #
innodb_buffer_pool_size = 256M #缓存池大小
max_connections = 2000 #最大连接数
log-bin = master-log #开启二进制日志

@ -0,0 +1,4 @@
---
# handlers file for mariadb
- name: restart
service: name=mariadb state=restarted

@ -0,0 +1,53 @@
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.9
# 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,18 @@
---
# tasks file for mariadb
- name: copy yum repostory
copy: src=mariadb.repo dest=/etc/yum.repos.d/mariadb.repo
- name: install mariadb
yum: name=MariaDB-server,MariaDB-client state=present
- name: copy mariadb config file
copy: src=my.cnf dest=/etc/my.cnf.d/server.cnf
notify: restart
- name: start service
service: name=mariadb state=started
- name: init database
shell: mysql -e "create database {{ dbName }} character set utf8 collate utf8_bin; grant all on {{ dbName }}.* to '{{ dbUser }}'@'%' identified by '{{ dbPassword }}';flush privileges;"

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

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

@ -0,0 +1,5 @@
---
- hosts: server
remote_user: root
roles:
- zabbix-server

@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

@ -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,2 @@
---
# defaults file for zabbix-agentd

@ -0,0 +1,2 @@
---
# handlers file for zabbix-agentd

@ -0,0 +1,53 @@
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.9
# 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,2 @@
---
# tasks file for zabbix-agentd

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

@ -0,0 +1,2 @@
---
# vars file for zabbix-agentd

@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

@ -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,2 @@
---
# defaults file for zabbix-server

@ -0,0 +1,75 @@
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/opt/rh/rh-nginx116/log/nginx/error.log;
pid /var/opt/rh/rh-nginx116/run/nginx/nginx.pid;
# Load dynamic modules. See /opt/rh/rh-nginx116/root/usr/share/doc/README.dynamic.
include /opt/rh/rh-nginx116/root/usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/opt/rh/rh-nginx116/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/opt/rh/rh-nginx116/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/opt/rh/rh-nginx116/nginx/conf.d/*.conf;
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}

@ -0,0 +1,5 @@
---
# handlers file for zabbix-server
- name: restart service
service: name=zabbix-server state=restarted

@ -0,0 +1,53 @@
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.9
# 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,38 @@
---
# tasks file for zabbix-server
- name: install zabbix-server {{ zabbixServerLevel }} yum repostory
yum: name="https://repo.zabbix.com/zabbix/{{ zabbixServerLevel }}/rhel/7/x86_64/zabbix-release-{{ zabbixServerLevel }}-1.el7.noarch.rpm" state=present
- name: install zabbix-server {{ zabbixServerLevel }} package
yum: name=zabbix-agent,zabbix-get,zabbix-sender,zabbix-server-mysql state=present
- name: input zabbix-server {{ zabbixServerLevel }} data
shell: zcat /usr/share/doc/zabbix-server-mysql-{{ zabbixServerLevel }}*/create.sql.gz | mysql -u{{ dbUser }} -p{{ dbPassword }} -h {{ database }} {{ dbName }}
- name: copy zabbix-server {{ zabbixServerLevel }} config file
template: src=zabbix_server.conf.j2 dest=/etc/zabbix/zabbix_server.conf backup=yes
notify: restart service
- name: start zabbix-server
service: name=zabbix-server state=started
# webui config
- name: install repo
yum: name=centos-release-scl state=present
- name: install zabbix webui
yum: name=zabbix-web-mysql-scl,zabbix-nginx-conf-scl state=present enablerepo=zabbix-frontend
- name: copy nginx config file
copy: src=nginx.conf dest=/etc/opt/rh/rh-nginx116/nginx/nginx.conf
- name: config
shell: sed -i.bak 's/listen.acl_users.*/listen\.acl_users=apache,nginx/;s@; php_value\[date\.timezone\].*@php_value[date.timezone]=Asia/Shanghai@' /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
- name: service start
service: name={{ item }} state=restarted enabled=yes
with_items:
- zabbix-server
- zabbix-agent
- rh-nginx116-nginx
- rh-php72-php-fpm

@ -0,0 +1,17 @@
ListenPort=10051
SourceIP={{ ansible_ens33['ipv4']['address'] }}
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/var/run/zabbix/zabbix_server.pid
SocketDir=/var/run/zabbix
DBHost={{ database }}
DBName={{ dbName }}
DBUser={{ dbUser }}
DBPassword={{ dbPassword }}
DBPort=3306
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
AlertScriptsPath=/usr/lib/zabbix/alertscripts
ExternalScripts=/usr/lib/zabbix/externalscripts
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1

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

@ -0,0 +1,4 @@
---
# vars file for zabbix-server
zabbixServerLevel: 5.0
database: 192.168.241.165
Loading…
Cancel
Save