first commit

This commit is contained in:
2021-08-28 23:54:41 +08:00
commit 06f4bf327a
55 changed files with 650 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
task: none
root_dir: /attachment
apk: none

3
roles/apk/tasks/main.yml Normal file
View File

@@ -0,0 +1,3 @@
---
- import_tasks: "{{task|lower}}.yml"

View File

@@ -0,0 +1,9 @@
---
- name: check whether {{apk}}.apk.bak exists
shell: cd {{root_dir}} && [ -f {{apk}}.apk.bak ]
ignore_errors: true
register: result
- name: revert {{apk}}.apk.bak
when: result is succeeded
shell: cd {{root_dir}} && rm -f {{apk}}.apk && mv {{apk}}.apk.bak {{apk}}.apk

View File

@@ -0,0 +1,15 @@
---
- name: upload {{apk}}.apk.zip
copy: src=/gxfp/transfer/{{apk}}.apk.zip dest={{root_dir}}/{{apk}}.zip
- name: check whether {{apk}}.apk exists
shell: cd {{root_dir}} && [ -f {{apk}}.apk ]
ignore_errors: true
register: result
- name: remove old {{apk}}.apk.bak
shell: cd {{root_dir}} && rm -f {{apk}}.apk.bak
- name: create current {{apk}}.apk.bak
shell: cd {{root_dir}} && mv {{apk}}.apk {{apk}}.apk.bak
when: result is succeeded
- name: unzip new {{apk}}.zip
shell: cd {{root_dir}} && unzip -o -qq {{apk}}.zip && rm -f {{apk}}.zip

View File

@@ -0,0 +1,10 @@
---
root_dir: "/home/repos"
svn_opt: "--username xxxx --password xxxx --non-interactive"
target_dir: "{{root_dir}}/{{repo}}/target"
svn_url: "svn://xxx.xxx.xxx.xxx/xx/xx"
svn_opt: ""
repo: "{{svn_url|basename}}"
remote_dir: "/path/to/deploy/remote"
f_make: false

3
roles/jar/tasks/main.yml Normal file
View File

@@ -0,0 +1,3 @@
---
- import_tasks: "{{task|lower}}.yml"

4
roles/jar/tasks/mvn.yml Normal file
View File

@@ -0,0 +1,4 @@
---
- name: build with mvn
shell: cd {{root_dir}}/{{repo}} && mvn clean package &>> {{ansible_env.SSH_TTY}}

View File

@@ -0,0 +1,9 @@
---
- name: check whether {{repo}}.jar.bak exists
shell: cd {{remote_dir}} && [ -f {{repo}}.jar.bak ]
ignore_errors: true
register: result
- name: revert {{repo}}.jar.bak
when: result is succeeded
shell: cd {{remote_dir}} && rm -f {{repo}}.jar && mv {{repo}}.jar.bak {{repo}}.jar

View File

@@ -0,0 +1,6 @@
---
- name: start {{repo}}
service: name={{repo}} state=started
#- name: wait for {{repo}} to start completely
#shell: while sleep 2; do grep -m 1 '(JVM running for [0-9\.]\+)$' {{remote_dir}}/../logs/{{repo}}.log && break; done

View File

@@ -0,0 +1,8 @@
---
- name: wait 2s to free connections
shell: sleep 2
- name: stop {{repo}}
service: name={{repo}} state=stopped
#- name: clean {{repo}} logs
#shell: cd {{remote_dir}}/../logs/{{repo}} && rm -f *

16
roles/jar/tasks/svn.yml Normal file
View File

@@ -0,0 +1,16 @@
---
- name: check whether {{repo}} exists
shell: ls {{repo}}/.svn || true
args:
chdir: "{{root_dir}}"
register: repo_exists
- name: checkout {{repo}} from svn
shell: cd {{root_dir}} && rm -rf {{repo}} && svn checkout {{svn_opt}} {{svn_url}} {{repo}} &>> {{ansible_env.SSH_TTY}}
when: repo_exists.stdout == ''
- name: update {{repo}} from svn
shell: cd {{root_dir}}/{{repo}} && svn update {{svn_opt}} &>> {{ansible_env.SSH_TTY}}
register: update_result
when: repo_exists.stdout != ''

View File

@@ -0,0 +1,18 @@
---
- name: upload {{repo}}.jar
copy: src={{target_dir}}/{{repo}}.jar dest={{remote_dir}}/{{repo}}.jar.new
- name: remove old {{repo}}.jar.bak
shell: cd {{remote_dir}} && rm -f {{repo}}.jar.bak
- name: check whether {{repo}}.jar exists
shell: cd {{remote_dir}} && ls {{repo}}.jar || true
register: jar_exists
- name: create current {{repo}}.jar.bak
shell: cd {{remote_dir}} && mv {{repo}}.jar {{repo}}.jar.bak
when: jar_exists.stdout != ''
- name: create new {{repo}}.jar
shell: cd {{remote_dir}} && mv {{repo}}.jar.new {{repo}}.jar

View File

@@ -0,0 +1,6 @@
---
task: none
ip: none
root_dir: /html
web: none

View File

@@ -0,0 +1,4 @@
---
- name: comment {{ip}} in upstream.conf
shell: cd /etc/nginx/conf.d && sed -i "/^ *server {{ip}}/s/^/#/" upstream.conf && nginx -s reload

View File

@@ -0,0 +1,4 @@
---
- name: uncomment {{ip}} in upstream.conf
shell: cd /etc/nginx/conf.d && sed -i "/^# *server {{ip}}/s/^#//" upstream.conf && nginx -s reload

View File

@@ -0,0 +1,3 @@
---
- import_tasks: "{{task|lower}}.yml"

View File

@@ -0,0 +1,4 @@
---
- name: restart nginx
service: name=nginx state=restarted

View File

@@ -0,0 +1,4 @@
---
- name: start nginx
service: name=nginx state=started

View File

@@ -0,0 +1,4 @@
---
- name: stop nginx
service: name=nginx state=stopped

View File

@@ -0,0 +1,6 @@
---
svn_url: "svn://xxx.xxx.xxx.xxx/xx/xx"
svn_opt: "--username xxxx --password xxxx --non-interactive"
repo: "{{svn_url|basename}}"
remote_dir: "/path/to/deploy/remote"

View File

@@ -0,0 +1,3 @@
---
- import_tasks: "{{task|lower}}.yml"

View File

@@ -0,0 +1,6 @@
---
- name: start {{repo}}
service: name={{repo}} state=started
#- name: wait for {{repo}} to start completely
#shell: while sleep 2; do grep -m 1 '(JVM running for [0-9\.]\+)$' {{remote_dir}}/../logs/{{repo}}.log && break; done

View File

@@ -0,0 +1,8 @@
---
- name: wait 2s to free connections
shell: sleep 2
- name: stop {{repo}}
service: name={{repo}} state=stopped
#- name: clean {{repo}} logs
#shell: cd {{remote_dir}}/../logs/{{repo}} && rm -f *

View File

@@ -0,0 +1,16 @@
---
- name: check whether {{repo}} exists
shell: ls {{repo}}/.svn || true
args:
chdir: "{{remote_dir}}"
register: repo_exists
- name: checkout {{repo}} from svn
shell: cd {{remote_dir}} && rm -rf {{repo}} && svn checkout {{svn_opt}} {{svn_url}} {{repo}} &>> {{ansible_env.SSH_TTY}}
when: repo_exists.stdout == ''
- name: update {{repo}} from svn
shell: cd {{remote_dir}}/{{repo}} && svn update {{svn_opt}} &>> {{ansible_env.SSH_TTY}}
register: update_result
when: repo_exists.stdout != ''

View File

@@ -0,0 +1,5 @@
---
task: none
app: none
root_dir: /tomcat

View File

@@ -0,0 +1,3 @@
---
- import_tasks: "{{task|lower}}.yml"

View File

@@ -0,0 +1,4 @@
---
- debug:
msg: "nothing to do ..."

View File

@@ -0,0 +1,9 @@
---
- name: check whether {{app}}.war.bak exists
shell: cd {{root_dir}}/webapps/ && [ -f {{app}}.war.bak ]
ignore_errors: true
register: result
- name: revert {{app}}.war.bak
when: result is succeeded
shell: cd {{root_dir}}/webapps/ && rm -rf {{app}}.war {{app}} && mv {{app}}.war.bak {{app}}.war

View File

@@ -0,0 +1,9 @@
---
- name: check whether {{app}}_backup.tgz exists
shell: cd {{root_dir}}/webapps/ && [ -f {{app}}_backup.tgz ]
ignore_errors: true
register: result
- name: revert {{app}}_backup.tgz
when: result is succeeded
shell: cd {{root_dir}}/webapps/ && rm -rf {{app}} && tar zxf {{app}}_backup.tgz && rm -f {{app}}_backup.tgz

View File

@@ -0,0 +1,8 @@
---
- name: start tomcat
service: name=tomcat state=started
- name: wait for tomcat to start completely
shell: while sleep 2; do grep -m 1 'Server startup in [0-9]\+ ms$' {{root_dir}}/logs/catalina.out && break; done
- name: link /dev/null to catalina.out
shell: cd {{root_dir}}/logs/ && rm -f catalina.out && ln -sf /dev/null catalina.out

View File

@@ -0,0 +1,8 @@
---
- name: wait 4s to free tomcat connections
shell: sleep 4
- name: stop tomcat
service: name=tomcat state=stopped
- name: clean catalina.out
shell: cd {{root_dir}}/logs/ && rm -f catalina.out && touch catalina.out

View File

@@ -0,0 +1,15 @@
---
- name: upload {{app}}.zip
copy: src=/var/transfer/{{app}}.zip dest={{root_dir}}/webapps/{{app}}.zip
- name: check whether {{app}}.war exists
shell: cd {{root_dir}}/webapps/ && [ -f {{app}}.war ]
ignore_errors: true
register: result
- name: remove old {{app}}.war.bak
shell: cd {{root_dir}}/webapps/ && rm -rf {{app}}.war.bak {{app}}
- name: create current {{app}}.war.bak
when: result is succeeded
shell: cd {{root_dir}}/webapps/ && mv {{app}}.war {{app}}.war.bak
- name: unzip new {{app}}.zip
shell: cd {{root_dir}}/webapps/ && unzip -o -qq {{app}}.zip && rm -f {{app}}.zip

View File

@@ -0,0 +1,15 @@
---
- name: upload {{app}}.zip
copy: src=/var/transfer/{{app}}.zip dest={{root_dir}}/webapps/{{app}}.zip
- name: check whether {{app}} exists
shell: cd {{root_dir}}/webapps/ && [ -d {{app}} ]
ignore_errors: true
register: result
- name: remove old {{app}}_backup.tgz
shell: cd {{root_dir}}/webapps/ && rm -rf {{app}}_backup.tgz
- name: create current {{app}}_backup.tgz
when: result is succeeded
shell: cd {{root_dir}}/webapps/ && tar zcf {{app}}_backup.tgz {{app}}/
- name: unzip new {{app}}.zip
shell: cd {{root_dir}}/webapps/ && unzip -o -qq {{app}}.zip && rm -f {{app}}.zip

View File

@@ -0,0 +1,8 @@
---
root_dir: "/home/repos"
svn_opt: "--username xxxx --password xxxx --non-interactive"
svn_url: "svn://xxx.xxx.xxx.xxx/xx/xx"
repo: "{{svn_url|basename}}"
remote_dir: "/path/to/deploy/remote"
f_make: false

3
roles/web/tasks/main.yml Normal file
View File

@@ -0,0 +1,3 @@
---
- import_tasks: "{{task|lower}}.yml"

4
roles/web/tasks/node.yml Normal file
View File

@@ -0,0 +1,4 @@
---
- name: build with node
shell: cd {{root_dir}}/{{repo}} && mvn clean package &>> {{ansible_env.SSH_TTY}}

View File

@@ -0,0 +1,9 @@
---
- name: check whether {{repo}}.jar.bak exists
shell: cd {{remote_dir}} && [ -f {{repo}}.jar.bak ]
ignore_errors: true
register: result
- name: revert {{repo}}.jar.bak
when: result is succeeded
shell: cd {{remote_dir}} && rm -f {{repo}}.jar && mv {{repo}}.jar.bak {{repo}}.jar

View File

@@ -0,0 +1,6 @@
---
- name: start {{repo}}
service: name={{repo}} state=started
#- name: wait for {{repo}} to start completely
#shell: while sleep 2; do grep -m 1 '(JVM running for [0-9\.]\+)$' {{remote_dir}}/../logs/{{repo}}.log && break; done

View File

@@ -0,0 +1,8 @@
---
- name: wait 2s to free connections
shell: sleep 2
- name: stop {{repo}}
service: name={{repo}} state=stopped
#- name: clean {{repo}} logs
#shell: cd {{remote_dir}}/../logs/{{repo}} && rm -f *

15
roles/web/tasks/svn.yml Normal file
View File

@@ -0,0 +1,15 @@
---
- name: check whether {{repo}} exists
shell: cd {{root_dir}} && [ -d {{repo}}/.svn ]
ignore_errors: true
register: repo_exists
- name: checkout {{repo}} from svn
shell: cd {{root_dir}} && rm -rf {{repo}} && svn checkout {{svn_opt}} {{svn_url}} {{repo}} &>> {{ansible_env.SSH_TTY}}
when: repo_exists is failed
- name: update {{repo}} from svn
shell: cd {{root_dir}}/{{repo}} && svn update {{svn_opt}} &>> {{ansible_env.SSH_TTY}}
register: update_result
when: repo_exists is succeeded

View File

@@ -0,0 +1,10 @@
---
- name: upload {{repo}}.jar
copy: src={{root_dir}}/{{repo}}/target/{{repo}}.jar dest={{remote_dir}}/{{repo}}.jar.new
- name: remove old {{repo}}.jar.bak
shell: cd {{remote_dir}} && rm -f {{repo}}.jar.bak
- name: create current {{repo}}.jar.bak
shell: cd {{remote_dir}} && mv {{repo}}.jar {{repo}}.jar.bak
- name: create new {{repo}}.jar
shell: cd {{remote_dir}} && mv {{repo}}.jar.new {{repo}}.jar

View File

@@ -0,0 +1,3 @@
---
task: none

View File

@@ -0,0 +1,8 @@
---
- name: cat zookeeper id
shell: cat /data/zookeeper/data/myid
register: output
- name: print zookeeper id
debug:
msg: "zookeeper id: {{ output.stdout }}"

View File

@@ -0,0 +1,3 @@
---
- import_tasks: "{{task|lower}}.yml"

View File

@@ -0,0 +1,4 @@
---
- name: restart zookeeper
service: name=zookeeper state=restarted

View File

@@ -0,0 +1,4 @@
---
- name: start zookeeper
service: name=zookeeper state=started

View File

@@ -0,0 +1,4 @@
---
- name: stop zookeeper
service: name=zookeeper state=stopped