Files
ansible/oldstuff/tasks/install-axinstall-cilcompile.yaml
2024-09-12 09:27:25 +00:00

108 lines
3.6 KiB
YAML

---
- name: Send notification message via Slack
delegate_to: localhost
community.general.slack:
token: "{{ slack_token }}"
msg: Starting Ax service on {{ inventory_hostname }}
- name: Start Ax service
ansible.windows.win_service:
name: aos60$01
state: started
start_mode: auto
- name: Send notification message via Slack
delegate_to: localhost
community.general.slack:
token: "{{ slack_token }}"
msg: Starting CIL compile on {{ inventory_hostname }}
#- name: Compile CIL using Invoke-AxaptaServerCmd
# ansible.windows.win_shell: |
# $null = . 'D:\Program Files\Microsoft Dynamics AX\60\ManagementUtilities\Microsoft.Dynamics.ManagementUtilities.ps1'
# $AOSInstanceName = (Get-WmiObject -Class "MicrosoftDynamicsAX|InstalledAOSInstances" -Namespace "root\MicrosoftDynamicsAX").InstanceName
# $output = Invoke-AxaptaServerCmd -Server $AOSInstanceName -Command "CompileIL"
# register: cil_compile_output
# tags:
# - ax_compile_cil
- name: Compile CIL using AX32.exe
win_shell: |
$startupCmd = "-startupcmd=CompileIL"
$createDesktopA = @"
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr CreateDesktopA(string lpszDesktop, IntPtr lpszDevice, IntPtr pDevmode, uint dwFlags, uint dwDesiredAccess, IntPtr lpsa);
"@
Add-Type -MemberDefinition $createDesktopA -Name "NativeMethods" -Namespace "Win32"
$desktop = [Win32.NativeMethods]::CreateDesktopA("CustomDesktop", [IntPtr]::Zero, [IntPtr]::Zero, 0, 0x10000000, [IntPtr]::Zero)
$job = Start-Job -ScriptBlock {Start-Process -FilePath "ax32.exe" -ArgumentList "-startupcmd=CompileIL" -Wait}
Wait-Job $job
register: cil_compile_output
tags:
- ax_compile_cil
- name: Check CIL compilation result
win_shell: |
$logFilePath = "D:\Program Files\Microsoft Dynamics AX\60\Server\TravelCardDynamicsAX\bin\XppIL\Dynamics.Ax.Application.dll.log"
if (Test-Path $logFilePath) {
$logContent = Get-Content $logFilePath -Raw -Encoding UTF8
$errors = Select-String -Path $logFilePath -Pattern "Error"
$warnings = Select-String -Path $logFilePath -Pattern "Warning"
if ($logContent -match "Finished creating types.") {
Write-Output "CIL compilation succeeded."
Write-Host "Number of Errors: $($errors.Line)"
Write-Host "Number of Warnings: $($warnings.Line)"
} else {Write-Output "CIL compilation failed."
}
}
else {
Write-Output "Log file not found."
}
register: cil_compile_output
tags:
- ax_compile_cil
- name: Send CIL compilation result notification via Slack
delegate_to: localhost
community.general.slack:
token: "{{ slack_token }}"
msg: |
CIL compilation result for {{ inventory_hostname }}:
{{ cil_compile_output.stdout_lines}}
tags:
- ax_compile_cil
#- name: Show CIL compilation result
# ansible.builtin.debug:
# var: cil_compile_output.stdout_lines
# tags:
# - ax_compile_cil
#
#- name: Send CIL compilation result notification via Slack
# delegate_to: localhost
# community.general.slack:
# token: "{{ slack_token }}"
# msg: |
# CIL compilation result for {{ inventory_hostname }}:
# {% if cil_compile_output.stdout_lines %}
# {% for line in cil_compile_output.stdout_lines %}
# {{ line }}
# {% endfor %}
# {% else %}
# No output received.
# {% endif %}
# tags:
# - ax_compile_cil
- name: Send notification message via Slack
delegate_to: localhost
community.general.slack:
token: "{{ slack_token }}"
msg: Stopping Ax service on {{ inventory_hostname }}
- name: Stop Ax service
ansible.windows.win_service:
name: aos60$01
state: stopped
start_mode: auto