Score:0

Ansible uninstall application, stop restart services

us flag

I am in need of creating a playbook that:

  1. checks if application1 is installed - if fails then exit this host and move on to next host
  2. checks if application2 is installed - if fails then exit & move onto next host
  3. stopping application2 services
  4. uninstall application1 - make sure application2 services are stopped before installing appliction3 - install application3 then
  5. start application2 services
#################################################
    - Playbook Identify if applications are installed 
      - tasks 
      - name: check if application1 is installed if yes continue
          win_shell: |
          $application1 = ("","Wow6432Node: |ForEach-Object {Get-ChildItem HKLM:/SOFTWARE\$_\Microsoft\hostname }}"Windows\CurrentVersion\Uninstall\}
          select@(n=Name;e={$.getvalue("displayname")}} Where {$. -like "*application1*"}).name.length -gt 0
        with_items:"{{ hostname }}"
        changed_when: false
        ignore_errors: true
        register: output
        win_shell: echo output.stdout
    EXIT LOGIC
    
      - name: check if application2 is installed if yes continue
          win_shell: |
          $application1 = ("","Wow6432Node: |ForEach-Object {Get-ChildItem HKLM:/SOFTWARE\$_\Microsoft\hostname }}"Windows\CurrentVersion\Uninstall\}
          select@(n=Name;e={$.getvalue("displayname")}} Where {$. -like "*application2*"}).name.length -gt 0
        with_items:"{{ hostname }}"
        changed_when: false
        ignore_errors: true
        register: output2
        win_shell: echo output2.stdout
    EXIT LOGIC
    
    #################################################
      - name: stopping application2 services
        win_shell: Stop-Process -Name "Application2*" -Force
        with_items"{{ hostname" }}
        changed_when: false
        ignore_errors: true
        register:installed
      - debug: msg="Stop Application2 Services"
    #################################################
    
      - name: uninstall application1
        win_command: C:\Windows\System32\msiexec.exe /i C:\Program Files (x86)\Application1\uninstall.exe /qn /norestart
        register:application1uninstall
    
      - name: Installing Application3 using win_command
        win_command: Application3_installer.exe
        register:application3install
    
    #################################################
      - name: Starting Application2 services
        win_service:
          name: Application2
          state:started
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.