From 7d5f86b045ebb657d0efa9c191a4c1b79720984e Mon Sep 17 00:00:00 2001 From: Valentin CZERYBA Date: Sun, 12 Feb 2023 22:28:32 +0100 Subject: [PATCH] test configure and deconfigure --- inventory/host_vars/vps-host | 34 +++++++++---------- .../getinfo_day.sh} | 2 +- roles/deploy-web/tasks/blacklist.yml | 2 ++ roles/deploy-web/tasks/configure.yml | 9 ++--- roles/deploy-web/tasks/deconfigure.yml | 11 +++--- roles/deploy-web/tasks/deconfigure_stats.yml | 15 ++++++-- roles/deploy-web/tasks/main.yml | 4 +-- roles/deploy-web/tasks/stats.yml | 14 +++++--- roles/deploy-web/tasks/supervision.yml | 1 + roles/deploy-web/templates/token.j2 | 1 + 10 files changed, 56 insertions(+), 37 deletions(-) rename roles/deploy-web/{templates/getinfo_day.sh.j2 => files/getinfo_day.sh} (98%) create mode 100644 roles/deploy-web/templates/token.j2 diff --git a/inventory/host_vars/vps-host b/inventory/host_vars/vps-host index 90d25f1..575c2a9 100644 --- a/inventory/host_vars/vps-host +++ b/inventory/host_vars/vps-host @@ -1,18 +1,18 @@ $ANSIBLE_VAULT;1.1;AES256 -62643736353737643733623031373139626437396435656664636661373730646535326539303362 -3562383661323166643437636233633838303861373230380a623939366265356531356131343062 -65306666333065336633333036626163313633646233313238373032323561626665356531653661 -6661393439386438360a376339663536313366653633363362323264346565313332366230326331 -66333630383639626262386332633462653635386137396231363763373466663463343961356137 -38643432316330366432333534343639663433333361343665376461333465306236353833313866 -37643531396639626461303538313465323663396436393365323663333363653835366637356339 -63316435346132383766363562356262396565303233336337366430323034383832633738616135 -64646232646237613736643134653264383963373935333766626461383939663538346466383731 -37643131663830653630633864306439613637363836646164356464623732356137656331343233 -66356534396239646266313063356333353232343263323139386337306135623063316439643861 -36323839393536323562323462376161376561653934366135376165656338656361333530646431 -39396461353432316537366433353765663234393932393536323963643631306563663133323930 -32396465646635336566623636353437626232343135623762343338323661363332653837316363 -39346334616339643062623731353035363433653163303062636362353235636265623533636634 -62326461356462363562373537363630303263653864323334326561326637636166346364626563 -3761 +31393265313635666339373930656266363533626234383533313734323964386463363739363664 +3362323965366165643139326433646535303931616338390a316232656464383534383361313032 +39303032376339303830643866356464303235633736623134313334646361363265393330653432 +6338626261383734380a333662613238323038616637643162626436376536326461396461303866 +36383835363639633530653238353564643438616238663263363837343436636531656332303266 +37303663303139393636663334313130356231643639633833636563356137393930383639613337 +31353336346531313561336464643332333234656236386330316236376234306463663164623435 +62386665383332316133383035366162323636323638323965643532356634333836323562303132 +61396539633336346436346466306339316461613732383738666663366233373261396366353039 +61303966326130326531393837333562383337646463393435643336303465393935623938346530 +64623864313332613633333162623736643030363833346133643838383534656430336332333331 +61383661353932383961303537306233333864623531316239653131346436313035643461633032 +33376338326466616230373465643236343937653839316562633630393162373936306364633765 +32306337656639386330386334653262313663363062356263623165366164663764646430373162 +36353539376234386465393637303533323662353965663936623464633066386239623637373539 +39323637653361663730633735396133636539303133306164373838623930663364306135353938 +3935 diff --git a/roles/deploy-web/templates/getinfo_day.sh.j2 b/roles/deploy-web/files/getinfo_day.sh similarity index 98% rename from roles/deploy-web/templates/getinfo_day.sh.j2 rename to roles/deploy-web/files/getinfo_day.sh index 83b549b..6866cb8 100755 --- a/roles/deploy-web/templates/getinfo_day.sh.j2 +++ b/roles/deploy-web/files/getinfo_day.sh @@ -2,7 +2,7 @@ MAIL=/tmp/mail DIRECTORY=/home/valentin/mail SERVER_LOG=/var/log/nginx -TOKEN={{ token_ipinfo }} +TOKEN=$(cat /etc/sentinel/token) DATE=$(date +%Y%m%d-%H%M%S) HOST=($(cat /etc/sentinel/virtualhost)) WEEK=$(date +%V) diff --git a/roles/deploy-web/tasks/blacklist.yml b/roles/deploy-web/tasks/blacklist.yml index 23df579..b584859 100644 --- a/roles/deploy-web/tasks/blacklist.yml +++ b/roles/deploy-web/tasks/blacklist.yml @@ -19,6 +19,8 @@ cron_file: "blacklist_cron" minute: "*/5" job: "bash /usr/local/bin/sentinel/blacklist.sh" + user: root + vars: ansible_become: yes ansible_become_method: sudo diff --git a/roles/deploy-web/tasks/configure.yml b/roles/deploy-web/tasks/configure.yml index d9f1a42..f483ce3 100644 --- a/roles/deploy-web/tasks/configure.yml +++ b/roles/deploy-web/tasks/configure.yml @@ -9,18 +9,19 @@ ansible_become: yes ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" - tags: [ "configure", "stats", "blacklist", "supervision"] + when: script is not defined + - name: Deploy stats script import_tasks: stats.yml - tags: [ "configure", "stats"] + when: script is not defined or script == "stats" - name: Configure blacklist script import_tasks: blacklist.yml - tags: [ "configure", "blacklist" ] + when: script is not defined or script == "blacklist" - name: Configure supervision script import_tasks: supervision.yml - tags: [ "configure", "supervision" ] \ No newline at end of file + when: script is not defined or script == "supervision" diff --git a/roles/deploy-web/tasks/deconfigure.yml b/roles/deploy-web/tasks/deconfigure.yml index 21e3c60..266d5bb 100644 --- a/roles/deploy-web/tasks/deconfigure.yml +++ b/roles/deploy-web/tasks/deconfigure.yml @@ -3,18 +3,19 @@ - name: Deconfigure stats script import_tasks: deconfigure_stats.yml - tags: [ "deconfigure", "stats"] + when: script is not defined or script == "stats" - name: Deconfigure blacklist script import_tasks: deconfigure_blacklist.yml - tags: [ "deconfigure", "blacklist" ] + when: script is not defined or script == "blacklist" + - name: Deconfigure supervision script import_tasks: deconfigure_supervision.yml - tags: [ "deconfigure", "supervision" ] + when: script is not defined or script == "supervision" - - name: Remove sentinel directory +- name: Remove sentinel directory file: state: absent path: "{{ item }}/sentinel" @@ -25,4 +26,4 @@ ansible_become: yes ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" - tags: [ "deconfigure", "stats", "blacklist", "supervision"] \ No newline at end of file + when: script is not defined diff --git a/roles/deploy-web/tasks/deconfigure_stats.yml b/roles/deploy-web/tasks/deconfigure_stats.yml index 4cd0ccc..330b61c 100644 --- a/roles/deploy-web/tasks/deconfigure_stats.yml +++ b/roles/deploy-web/tasks/deconfigure_stats.yml @@ -1,7 +1,7 @@ # tasks file for stats script -- name: Crontab get info day +- name: Remove crontab get info day ansible.builtin.cron: name: "get info day" cron_file: "get_info_day_cron" @@ -11,7 +11,7 @@ ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" -- name: Crontab get info week +- name: Remove crontab get info week ansible.builtin.cron: name: "get info week" cron_file: "get_info_week_cron" @@ -21,7 +21,7 @@ ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" -- name: Crontab get info month +- name: Remove crontab get info month ansible.builtin.cron: name: "get info month" cron_file: "get_info_month_cron" @@ -45,6 +45,15 @@ ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" +- name: Remove token + file: + path: "/etc/sentinel/token" + state: absent + vars: + ansible_become: yes + ansible_become_method: sudo + ansible_become_password: "{{ sudo_password }}" + - name: Remove template virtualhost file: path: /etc/sentinel/virtualhost diff --git a/roles/deploy-web/tasks/main.yml b/roles/deploy-web/tasks/main.yml index 63983af..f03c8a2 100644 --- a/roles/deploy-web/tasks/main.yml +++ b/roles/deploy-web/tasks/main.yml @@ -11,6 +11,6 @@ import_tasks: destroy.yml tags: ["destroy"] -- name: Configure project web - import_tasks: configure.yml +- name: Deconfigure project web + import_tasks: deconfigure.yml tags: [ "deconfigure" ] \ No newline at end of file diff --git a/roles/deploy-web/tasks/stats.yml b/roles/deploy-web/tasks/stats.yml index d6e7a4d..0c96977 100644 --- a/roles/deploy-web/tasks/stats.yml +++ b/roles/deploy-web/tasks/stats.yml @@ -10,22 +10,23 @@ ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" -- name: Template getinfo day script +- name: Template token ipinfo template: - src: getinfo_day.sh.j2 - dest: /usr/local/bin/sentinel/getinfo_day.sh + src: token.j2 + dest: /etc/sentinel/token mode: "0555" vars: ansible_become: yes ansible_become_method: sudo ansible_become_password: "{{ sudo_password }}" -- name: Copy getinfo month and week script +- name: Copy getinfo script copy: - src: "getinfo_{{ item }}.sh.j2" + src: "getinfo_{{ item }}.sh" dest: "/usr/local/bin/sentinel/getinfo_{{ item }}.sh" mode: "0555" with_items: + - day - week - month vars: @@ -39,6 +40,7 @@ cron_file: "get_info_day_cron" minute: "0" hour: "3" + user: root job: "bash /usr/local/bin/sentinel/getinfo_day.sh" vars: ansible_become: yes @@ -52,6 +54,7 @@ minute: "15" hour: "3" weekday: "1" + user: root job: "bash /usr/local/bin/sentinel/getinfo_week.sh" vars: ansible_become: yes @@ -65,6 +68,7 @@ minute: "30" hour: "3" day: "1" + user: root job: "bash /usr/local/bin/sentinel/getinfo_month.sh" vars: ansible_become: yes diff --git a/roles/deploy-web/tasks/supervision.yml b/roles/deploy-web/tasks/supervision.yml index b641ae8..6ed473a 100644 --- a/roles/deploy-web/tasks/supervision.yml +++ b/roles/deploy-web/tasks/supervision.yml @@ -15,6 +15,7 @@ name: "check ssl script" cron_file: "check_ssl_cron" minute: "*/30" + user: root job: "bash /usr/local/bin/sentinel/check_ssl.sh" vars: ansible_become: yes diff --git a/roles/deploy-web/templates/token.j2 b/roles/deploy-web/templates/token.j2 new file mode 100644 index 0000000..bcd9b81 --- /dev/null +++ b/roles/deploy-web/templates/token.j2 @@ -0,0 +1 @@ +{{ token_ipinfo }} \ No newline at end of file