Advertisement
D0cEvil

Ansible - Windows dotnet deploy

Dec 27th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 2.87 KB | Cybersecurity | 0 0
  1. # AUTOR: https://github.com/kot-lex/spbdotnet-ansible #
  2. - name: Setup App
  3.   hosts: webservers
  4.   tasks:
  5.     - name: Install IIS
  6.       win_feature:
  7.         name:
  8.        - Web-Server
  9.         - Web-Common-Http
  10.         include_sub_features: True
  11.         include_management_tools: True
  12.         state: present
  13.       register: win_feature  
  14.     - name: reboot if installing Web-Server feature requires it
  15.       win_reboot:
  16.       when: win_feature.reboot_required          
  17.  
  18. - name: SQL Server
  19.   hosts: dbservers
  20.   tasks:
  21.     - name: Install MS SQL Server 2014
  22.       win_chocolatey:
  23.         name: mssqlserver2014express
  24.         state: present
  25.  
  26. - name: Deploy IIS Web App
  27.   hosts: webservers
  28.   tasks:
  29.     - name: Ensure target directory exist
  30.       win_file:
  31.             path: C:\webapp
  32.             state: directory
  33.     - name: Copy artifacts to remote machine
  34.       win_copy:
  35.             src: files/WebApp.zip
  36.             dest: C:\webapp\WebApp.zip
  37.     - name: Unzip build artifacts
  38.       win_unzip:
  39.             src: C:\webapp\WebApp.zip
  40.             dest: C:\webapp
  41.     - name: Ensure that the WebApp application exists
  42.       win_iis_webapplication:
  43.           name: WebApp
  44.           physical_path: c:\webapp
  45.           site: Default Web Site
  46.           state: present
  47.  
  48. - name: Deploy binaries
  49.   hosts: webservers
  50.   vars:
  51.     myapp_artifacts: files/MyAppService.zip
  52.     myapp_workdir: C:\myapp
  53.   tasks:
  54.     - name: Get arifacts checksum
  55.       stat:
  56.         path: "{{ myapp_artifacts }}"
  57.       delegate_to: localhost
  58.       register: myapp_artifacts_stat
  59.  
  60.     - name: Get remote artifacts checksum
  61.       win_stat:
  62.         path: "{{ myapp_workdir }}\\MyAppService.zip"
  63.       register: myapp_remote_artifacts_stat
  64.  
  65.     - name: Stop play if checksums match
  66.       meta: end_play
  67.       when:
  68.        - myapp_artifacts_stat.stat.checksum is defined
  69.        - myapp_remote_artifacts_stat.stat.checksum is defined
  70.        - myapp_artifacts_stat.stat.checksum == myapp_remote_artifacts_stat.stat.checksum
  71.    
  72.     - name: Remove Service if exists
  73.       win_service:
  74.             name: MyAppService
  75.             state: absent
  76.             path: "{{ myapp_workdir }}\\MyAppService.exe"
  77.  
  78.     - name: Delete old files
  79.       win_file:
  80.             path: "{{ myapp_workdir }}\\"
  81.             state: absent  
  82.  
  83.     - name: Copy artifacts to remote machine
  84.       win_copy:
  85.             src: "{{ myapp_artifacts }}"
  86.             dest: "{{ myapp_workdir }}\\"
  87.  
  88.     - name: Unzip build artifacts
  89.       win_unzip:
  90.             src: "{{ myapp_workdir }}\\MyAppService.zip"
  91.             dest: "{{ myapp_workdir }}"
  92.  
  93.     - name: Register and start the service
  94.       win_service:
  95.             name: ReporterService
  96.             start_mode: auto
  97.             state: started
  98.             path: "{{ myapp_workdir }}\\MyAppService.exe"
  99.  
  100. # AUTOR: https://github.com/kot-lex/spbdotnet-ansible #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement