From 01890afdeaf895fd164913b3c1562b071293d278 Mon Sep 17 00:00:00 2001 From: qtsbautista-tip Date: Tue, 28 Sep 2021 19:32:46 +0800 Subject: [PATCH] activity7 Signed-off-by: qtsbautista-tip --- ansible.cfg | 12 +++++ elastic.repo | 9 ++++ grafana.repo | 10 ++++ inventory | 2 + playbook.yaml | 17 +++++++ prometheus.repo | 10 ++++ ubuntu_elastic/.travis.yml | 29 +++++++++++ ubuntu_elastic/README.md | 38 +++++++++++++++ ubuntu_elastic/inventory | 2 + ubuntu_elastic/main.yml | 31 ++++++++++++ ubuntu_elastic/test.yml | 5 ++ ubuntu_grafana/.travis.yml | 29 +++++++++++ ubuntu_grafana/inventory | 2 + ubuntu_grafana/main.yml | 20 ++++++++ ubuntu_grafana/test.yml | 5 ++ ubuntu_nagios/.travis.yml | 29 +++++++++++ ubuntu_nagios/inventory | 2 + ubuntu_nagios/main.yml | 92 +++++++++++++++++++++++++++++++++++ ubuntu_nagios/test.yml | 5 ++ ubuntu_prometheus/.travis.yml | 29 +++++++++++ ubuntu_prometheus/inventory | 2 + ubuntu_prometheus/main.yml | 7 +++ ubuntu_prometheus/test.yml | 5 ++ 23 files changed, 392 insertions(+) create mode 100644 ansible.cfg create mode 100644 elastic.repo create mode 100644 grafana.repo create mode 100644 inventory create mode 100644 playbook.yaml create mode 100644 prometheus.repo create mode 100644 ubuntu_elastic/.travis.yml create mode 100644 ubuntu_elastic/README.md create mode 100644 ubuntu_elastic/inventory create mode 100644 ubuntu_elastic/main.yml create mode 100644 ubuntu_elastic/test.yml create mode 100644 ubuntu_grafana/.travis.yml create mode 100644 ubuntu_grafana/inventory create mode 100644 ubuntu_grafana/main.yml create mode 100644 ubuntu_grafana/test.yml create mode 100644 ubuntu_nagios/.travis.yml create mode 100644 ubuntu_nagios/inventory create mode 100644 ubuntu_nagios/main.yml create mode 100644 ubuntu_nagios/test.yml create mode 100644 ubuntu_prometheus/.travis.yml create mode 100644 ubuntu_prometheus/inventory create mode 100644 ubuntu_prometheus/main.yml create mode 100644 ubuntu_prometheus/test.yml diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 000000000..c0ad16d79 --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,12 @@ +[defaults] + +inventory = ./inventory +remote_user = qtsbautista +deprecaion_warnings = false + +[privilege_escalation] + +become = true +become_user = root +become_method = sudo +become_ask_pass = false diff --git a/elastic.repo b/elastic.repo new file mode 100644 index 000000000..fa76c9564 --- /dev/null +++ b/elastic.repo @@ -0,0 +1,9 @@ +[elasticstack] + +name=Elastic repository for 7.x packages +baseurl=https://artifacts.elastic.co/packages/7.x/yum +gpgcheck=1 +gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch +enabled=1 +autorefresh=1 +type=rpm-md diff --git a/grafana.repo b/grafana.repo new file mode 100644 index 000000000..be440ac79 --- /dev/null +++ b/grafana.repo @@ -0,0 +1,10 @@ +[gafana] + +name=Grafana Repository +baseurl=https://packages.grafana.com/oss/rpm +repo_gpgcheck=1 +enabled=1 +gpgcheck=1 +gpgkey=https://packages.grafana.com/gpg.key +sslverify=1 +sslcacert=/etc/pki/tls/certs/ca-bundle.crt diff --git a/inventory b/inventory new file mode 100644 index 000000000..c005fe376 --- /dev/null +++ b/inventory @@ -0,0 +1,2 @@ +[ubuntu] +192.168.1.121 diff --git a/playbook.yaml b/playbook.yaml new file mode 100644 index 000000000..4c5e92851 --- /dev/null +++ b/playbook.yaml @@ -0,0 +1,17 @@ +--- +- name: install packages ubuntu + hosts: ubuntu + roles: + - ubuntu_elastic + - ubuntu_grafana + - ubuntu_nagios + - ubuntu_prometheus + +- name: install packages ubuntu + hosts: ubuntu + roles: + - ubuntu_elastic + - ubuntu_grafana + - ubuntu_nagios + - ubuntu_prometheus + diff --git a/prometheus.repo b/prometheus.repo new file mode 100644 index 000000000..e20ccd6ab --- /dev/null +++ b/prometheus.repo @@ -0,0 +1,10 @@ +[prometheus] + +name=Prometheus Repository +baseurl=https://packagecloud.io/prometheus-rpm/release/el/$releasever/$basearch +repo_gpgcheck=1 +enabled=1 +gpgkey=https://packagecloud.io/prometheus-rpm/release/gpgkey + https://raw.githubusercontent.com/lest/prometheus-rpm/master/RPM-GPG-KEY-prometheus-rpm +gpgcheck=1 +metadata_expire=300 diff --git a/ubuntu_elastic/.travis.yml b/ubuntu_elastic/.travis.yml new file mode 100644 index 000000000..fb7adb545 --- /dev/null +++ b/ubuntu_elastic/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "20.0.2" + +# 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/ diff --git a/ubuntu_elastic/README.md b/ubuntu_elastic/README.md new file mode 100644 index 000000000..225dd44b9 --- /dev/null +++ b/ubuntu_elastic/README.md @@ -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). diff --git a/ubuntu_elastic/inventory b/ubuntu_elastic/inventory new file mode 100644 index 000000000..c005fe376 --- /dev/null +++ b/ubuntu_elastic/inventory @@ -0,0 +1,2 @@ +[ubuntu] +192.168.1.121 diff --git a/ubuntu_elastic/main.yml b/ubuntu_elastic/main.yml new file mode 100644 index 000000000..5f8b31c8f --- /dev/null +++ b/ubuntu_elastic/main.yml @@ -0,0 +1,31 @@ +--- +# tasks file for roles/ubuntu_elastic +- name: add gpg key + apt_key: + url: https://artifacts.elastic.co/GPG-KEY-elasticsearch + state: present + +- name: add elk repository + shell: echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list + +- name: update ubuntu + become: yes + apt: + upgrade: 'yes' + update_cache: yes + +- name: install elasticsearch + apt: + name: elasticsearch + state: present + +- name: install logstash + apt: + name: logstash + state: present + +- name: install kibana + apt: + update_cache: yes + name: kibana + state: present diff --git a/ubuntu_elastic/test.yml b/ubuntu_elastic/test.yml new file mode 100644 index 000000000..ab99e59e7 --- /dev/null +++ b/ubuntu_elastic/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: ubuntu + remote_user: root + roles: + - roles/ubuntu_elastic diff --git a/ubuntu_grafana/.travis.yml b/ubuntu_grafana/.travis.yml new file mode 100644 index 000000000..fb7adb545 --- /dev/null +++ b/ubuntu_grafana/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "20.0.2" + +# 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/ diff --git a/ubuntu_grafana/inventory b/ubuntu_grafana/inventory new file mode 100644 index 000000000..c005fe376 --- /dev/null +++ b/ubuntu_grafana/inventory @@ -0,0 +1,2 @@ +[ubuntu] +192.168.1.121 diff --git a/ubuntu_grafana/main.yml b/ubuntu_grafana/main.yml new file mode 100644 index 000000000..47fc21f22 --- /dev/null +++ b/ubuntu_grafana/main.yml @@ -0,0 +1,20 @@ +--- +# tasks file for roles/ubuntu_grafana +- name: add grafana packages + apt_key: + url: https://packages.grafana.com/gpg.key + state: present + +- name: add grafana repo + shell: echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list + +- name: update ubuntu + become: yes + apt: + upgrade: 'yes' + update_cache: yes + +- name: install grafana in ubuntu + apt: + name: grafana + state: present diff --git a/ubuntu_grafana/test.yml b/ubuntu_grafana/test.yml new file mode 100644 index 000000000..0480617b1 --- /dev/null +++ b/ubuntu_grafana/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: ubuntu + remote_user: root + roles: + - roles/ubuntu_grafana diff --git a/ubuntu_nagios/.travis.yml b/ubuntu_nagios/.travis.yml new file mode 100644 index 000000000..fb7adb545 --- /dev/null +++ b/ubuntu_nagios/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "20.0.2" + +# 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/ diff --git a/ubuntu_nagios/inventory b/ubuntu_nagios/inventory new file mode 100644 index 000000000..c005fe376 --- /dev/null +++ b/ubuntu_nagios/inventory @@ -0,0 +1,2 @@ +[ubuntu] +192.168.1.121 diff --git a/ubuntu_nagios/main.yml b/ubuntu_nagios/main.yml new file mode 100644 index 000000000..8e0808d7a --- /dev/null +++ b/ubuntu_nagios/main.yml @@ -0,0 +1,92 @@ +--- +# tasks file for roles/ubuntu_nagios +- name: install packages in ubuntu + apt: + name: + - apache2 + - apache2-utils + - build-essential + - daemon + - libapache2-mod-php + - libgd-dev + - libperl-dev + - libssl-dev + - make + - openssl + - perl + - php + - php-gd + - unzip + - wget + state: latest + update_cache: yes + +- name: add group nagcmd + group: + name: nagcmd + state: present + +- name: add user nagios + user: + name: nagios + group: nagcmd + +- name: donwload and extract nagios core + unarchive: + src: https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.5.tar.gz + dest: /tmp + copy: no + +- name: configure nagios + command: ./configure --with-nagios-group=nagcmd --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled + args: + chdir: /tmp/nagios-4.4.5 + +- name: configure nagios clean + make: + target: clean + chdir: /tmp/nagios-4.4.5 + +- name: nagios compile + make: + target: all + chdir: /tmp/nagios-4.4.5 + +- name: install compilation nagios + make: + target: install + chdir: /tmp/nagios-4.4.5 + +- name: install init nagios + make: + target: install-init + chdir: /tmp/nagios-4.4.5 + +- name: install nagios config + make: + target: install-config + chdir: /tmp/nagios-4.4.5 + +- name: install nagios commandmode + make: + target: install-commandmode + chdir: /tmp/nagios-4.4.5 + +- name: install web interface + make: + target: install-webconf + chdir: /tmp/nagios-4.4.5 + +- name: add user account + htpasswd: + path: /usr/local/nagios/etc/htpasswd.users + name: user + password: password + +- name: a2enmod cgi + command: a2enmod cgi + +- name: restart apache2 + service: + name: apache2 + state: restarted diff --git a/ubuntu_nagios/test.yml b/ubuntu_nagios/test.yml new file mode 100644 index 000000000..d78fc6684 --- /dev/null +++ b/ubuntu_nagios/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: ubuntu + remote_user: root + roles: + - roles/ubuntu_nagios diff --git a/ubuntu_prometheus/.travis.yml b/ubuntu_prometheus/.travis.yml new file mode 100644 index 000000000..fb7adb545 --- /dev/null +++ b/ubuntu_prometheus/.travis.yml @@ -0,0 +1,29 @@ +--- +language: python +python: "20.0.2" + +# 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/ diff --git a/ubuntu_prometheus/inventory b/ubuntu_prometheus/inventory new file mode 100644 index 000000000..c005fe376 --- /dev/null +++ b/ubuntu_prometheus/inventory @@ -0,0 +1,2 @@ +[ubuntu] +192.168.1.121 diff --git a/ubuntu_prometheus/main.yml b/ubuntu_prometheus/main.yml new file mode 100644 index 000000000..c25fcf432 --- /dev/null +++ b/ubuntu_prometheus/main.yml @@ -0,0 +1,7 @@ +--- +# tasks file for roles/ubuntu_prometheus +- name: install prometheus ubuntu + apt: + name: + - prometheus + - prometheus-node-exporter diff --git a/ubuntu_prometheus/test.yml b/ubuntu_prometheus/test.yml new file mode 100644 index 000000000..80b45c91a --- /dev/null +++ b/ubuntu_prometheus/test.yml @@ -0,0 +1,5 @@ +--- +- hosts: ubuntu + remote_user: root + roles: + - roles/ubuntu_prometheus