2021-09-07

[jenkins@stg-cnaws-adm01 ~]$
[jenkins@stg-cnaws-adm01 ~]$ vim /data/scripts/deploy-war/deploy.yaml [jenkins@stg-cnaws-adm01 ~]$ more /data/scripts/deploy-war/deploy.yaml

  • hosts: ‘{{ remote_server }}’
    become: yes
    become_method: sudo
    become_user: billing
    tasks:
    • name: get billing id
      command: “whoami”
      register: login_user
      #become: yes
      #become_method: su
      #become_user: billing

    • name: echo login_user
      debug: msg=" login user is {{ login_user.stdout }}"

    • name: sendond get billing id
      command: “whoami”
      register: login_user2

    • name: echo login_user2
      debug: msg=" login user2 is {{ login_user2.stdout }}"

[jenkins@stg-cnaws-adm01 ~]$ /usr/bin/ansible-playbook /data/scripts/deploy-war/deploy.yaml -u jenkins.scheckout-stg -e remote_server=172.31.30.199

PLAY [172.31.30.199] ******************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************
ok: [172.31.30.199]

TASK [get billing id] *****************************************************************************************************
changed: [172.31.30.199]

TASK [echo login_user] ****************************************************************************************************
ok: [172.31.30.199] => {
“msg”: " login user is billing"
}

TASK [sendond get billing id] *********************************************************************************************
changed: [172.31.30.199]

TASK [echo login_user2] ***************************************************************************************************
ok: [172.31.30.199] => {
“msg”: " login user2 is billing"
}

PLAY RECAP ****************************************************************************************************************
172.31.30.199 : ok=5 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0


  • name: echo_info
    debug:
    msg: “target_server:{{ target_server }};
    project_name:{{ project_name }};
    pack_name:{{ pack_name }};
    config_dir:{{ config_dir }};
    app_dir:{{ app_dir }};
    ctrl_dir:{{ ctrl_dir }};
    version_date:{{ version_date }};
    app_run_user:{{ app_run_user }}”
    #project_name=“phub”
    #pack_name=“phub-svc”
    #config_dir="/iosp/comp/KaTeX parse error: Expected 'EOF', got '#' at position 40: …tion/gph/cfg/" #̲ctrl_dir="/iosp…{project_name}/configuration"
    #app_dir="/iosp/comp/${project_name}/configuration/deploy"
    #target_server=“172.31.30.199”
    #app_run_user=“phub”
    #version_date=“20210909”

  • name: Back and replace new war package
    get_url:
    url: “http://52.83.132.89/{{ project_name }}/{{ version_date }}/{{ pack_name}}.war”
    dest: “{{ app_dir }}/{{ pack_name }}.war”
    backup: yes
    mode: 0755

  • name: Back and replace billing’s new jar package
    get_url:
    url: “http://52.83.132.89/{{ project_name }}/{{ version_date }}/iospversion.jar”
    dest: “{{ app_dir }}/iospversion.jar”
    backup: yes
    when: app_run_user == “billing”

    ignore_errors: True

    #- block:

  • name: Back up old phub.tar and replace new phub.tar
    get_url:
    url: “http://52.83.132.89/{{ project_name }}/{{ version_date }}/phub.tar”
    dest: “{{ config_dir }}/phub.tar”
    backup: yes
    when: app_run_user == “phub”

  • name: unarchive file phub.tar
    unarchive:
    src: “{{ config_dir }}/phub.tar”
    dest: “{{ config_dir }}”
    remote_src: yes
    when: app_run_user == “phub”

  • name: unarchive file config.tar
    unarchive:
    src: “{{ config_dir }}/config.tar”
    dest: “{{ config_dir }}”
    remote_src: yes
    when: app_run_user == “billing”
    ignore_errors: True

    - name: Unarchive file config.tar

    unarchive:

    remote_src: yes

    src: “{{ config_dir }}/config.tar”

    dest: “{{ config_dir }}”

    when: update_config == ‘yes’

  • name: get_tomcat_pid
    shell: ps -ef | grep java | grep “/iosp/comp/{{ project_name }}/conf” | grep -v grep | awk ‘{print $2}’
    register: pid_num

  • name: echo tomcat_pid

    debug: msg=" tomcat pid is {{ pid_num.stdout }} "

    debug:
    msg: “old tomcat pid is {{ pid_num.stdout }}”
    ignore_errors: true

  • name: stop_tomcat
    shell: “sh service.sh stop chdir={{ ctrl_dir }}”
    tags: test-start

  • name: delete old version dir
    file:
    path: “{{ app_dir }}/webapps/ROOT”
    state: absent

  • name: start_tomcat
    #shell: sh service.sh start chdir={{ ctrl_dir }}

    shell: “nohup sh startup.sh & chdir={{ ctrl_dir }}”

    shell: “nohup sh startup.sh & chdir={{ ctrl_dir }}”
    tags: test-start

  • name: get_new_tomcat_pid
    shell: ps -ef | grep java | grep “/iosp/comp/{{ project_name }}/conf” | grep -v grep | awk ‘{print $2}’
    register: new_pid_num

  • name: echo new_tomcat_pid
    debug:
    msg: “new tomcat pid is {{ new_pid_num.stdout }}”
    ignore_errors: true

[jenkins@stg-cnaws-adm01 ~]$ cat /data/scripts_phub/deploy-war
deploy-war_phub/ deploy-war.yaml
[jenkins@stg-cnaws-adm01 ~]$ cat /data/scripts_phub/deploy-war_phub/
…、 tasks/ vars/
[jenkins@stg-cnaws-adm01 ~]$ cat /data/scripts_phub/deploy-war_phub/tasks/main.yaml

  • name: echo_info
    debug:
    msg: “target_server:{{ target_server }};
    project_name:{{ project_name }};
    pack_name:{{ pack_name }};
    config_dir:{{ config_dir }};
    app_dir:{{ app_dir }};
    ctrl_dir:{{ ctrl_dir }};
    version_date:{{ version_date }};
    app_run_user:{{ app_run_user }}”
    #project_name=“phub”
    #pack_name=“phub-svc”
    #config_dir="/iosp/comp/KaTeX parse error: Expected 'EOF', got '#' at position 40: …tion/gph/cfg/" #̲ctrl_dir="/iosp…{project_name}/configuration"
    #app_dir="/iosp/comp/${project_name}/configuration/deploy"
    #target_server=“172.31.30.199”
    #app_run_user=“phub”
    #version_date=“20210909”

  • name: Back and replace new war package
    get_url:
    url: “http://52.83.132.89/{{ project_name }}/{{ version_date }}/{{ pack_name}}.war”
    dest: “{{ app_dir }}/{{ pack_name }}.war”
    backup: yes
    mode: 0755

  • name: Back and replace billing’s new jar package
    get_url:
    url: “http://52.83.132.89/{{ project_name }}/{{ version_date }}/iospversion.jar”
    dest: “{{ app_dir }}/iospversion.jar”
    backup: yes
    when: app_run_user == “billing”

    ignore_errors: True

    #- block:

  • name: Back up old phub.tar and replace new phub.tar
    get_url:
    url: “http://52.83.132.89/{{ project_name }}/{{ version_date }}/phub.tar”
    dest: “{{ config_dir }}/phub.tar”
    backup: yes
    when: app_run_user == “phub”

  • name: unarchive file phub.tar
    unarchive:
    src: “{{ config_dir }}/phub.tar”
    dest: “{{ config_dir }}”
    remote_src: yes
    when: app_run_user == “phub”

  • name: unarchive file config.tar
    unarchive:
    src: “{{ config_dir }}/config.tar”
    dest: “{{ config_dir }}”
    remote_src: yes
    when: app_run_user == “billing”
    ignore_errors: True

    - name: Unarchive file config.tar

    unarchive:

    remote_src: yes

    src: “{{ config_dir }}/config.tar”

    dest: “{{ config_dir }}”

    when: update_config == ‘yes’

  • name: get_tomcat_pid
    shell: ps -ef | grep java | grep “/iosp/comp/{{ project_name }}/conf” | grep -v grep | awk ‘{print $2}’
    register: pid_num

  • name: echo tomcat_pid

    debug: msg=" tomcat pid is {{ pid_num.stdout }} "

    debug:
    msg: “old tomcat pid is {{ pid_num.stdout }}”
    ignore_errors: true

  • name: stop_tomcat
    shell: “sh service.sh stop chdir={{ ctrl_dir }}”
    tags: test-start

  • name: delete old version dir
    file:
    path: “{{ app_dir }}/webapps/ROOT”
    state: absent

  • name: start_tomcat
    #shell: sh service.sh start chdir={{ ctrl_dir }}

    shell: “nohup sh startup.sh & chdir={{ ctrl_dir }}”

    shell: “nohup sh startup.sh & chdir={{ ctrl_dir }}”
    tags: test-start

  • name: get_new_tomcat_pid
    shell: ps -ef | grep java | grep “/iosp/comp/{{ project_name }}/conf” | grep -v grep | awk ‘{print $2}’
    register: new_pid_num

  • name: echo new_tomcat_pid
    debug:
    msg: “new tomcat pid is {{ new_pid_num.stdout }}”
    ignore_errors: true

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值