Ensure that Ansible is installed before proceeding with the steps below.
If Ansible is not installed, follow the steps in this link - Installing Ansible on Windows via Ubuntu
Step 1: On the machine where the agent will be deployed, open PowerShell in administrator mode and execute the below command one by one.
Enable-PSRemoting -Force
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy
Open port 5985 on the Machine where the agent will be deployed.
Step 2: On the machine where Ansible is running, Create a file named host.yml with the content below.
[win]
<Machine_IP>
[win:vars]
ansible_user=<UserName>
ansible_password=<Password>
ansible_connection=winrm
ansible_winrm_transport=ntlm
ansible_winrm_scheme=http
ansible_winrm_server_cert_validation=ignore
ansible_shell_type=cmd
ansible_port=5985
ansible_winrm_read_timeout_sec=300
ansible_winrm_operation_timeout_sec=150
Update the values in the file as specified below.
<Machine_IP> = The machine_IP that wants to deploy the agent
<UserName> = Machine Username (Ensure the account has administrative privileges on the Windows machine.)
<Password> = Machine Password
Step 3: On the machine where Ansible is running, Create a file named Agent_deploy.yml with the following content.
- name: Create Directory on Windows
hosts: win
gather_facts: no
tasks:
- name: Change to the specific directory
win_shell: cd C:\
args:
chdir: C:\
- name: Execute PowerShell command in the specific directory
win_shell: |
# Your PowerShell command here
$env:PROTOCOL='CONTROLLER_PROTOCOL';$env:IP='CONTROLLER_IP';$env:PORT='CONTROLLER_PORT';$ProgressPreference='SilentlyContinue';Invoke-WebRequest -Uri CONTROLLER_PROTOCOL://CONTROLLER_IP:CONTROLLER_PORT/applicare/standalone?filename=windowsagentinstall.ps1 -OutFile $pwd\windowsagentinstall.ps1;./windowsagentinstall.ps1;
args:
chdir: C:\
- name: Run the BAT file
win_shell: |
.\agentscripts\createAgentTask.bat
args:
chdir: C:\ApplicareSingleAgentWindows
become: yes
become_user: <UserName>
become_method: runas
- name: Start the MyScheduledTask task
community.windows.win_scheduled_task:
name: StartSingleAgent
state: present
folder: "\"ApplicareAgent\""
actions:
- path: C:\ApplicareSingleAgentWindows\StartAgent.bat # Example action
arguments: test.txt # Optional arguments for the executable
Change the below values in the above file.
CONTROLLER_PROTOCOL -> http (or) https
CONTROLLER_IP -> Applicare Controller IP
CONTROLLER_PORT -> Applicare Controller Port
<UserName> = Machine Username (Ensure the account has administrative privileges on the Windows machine.)
Step 3: Navigate to the directory where the file was created and execute the below command.
ansible-playbook -i host.yml Agent_deploy.yml
Follow these steps only if you are updating the agent.
Step 1: On the machine where Ansible is running, Create a file named update_agent.yml with the following content.
---
- name: Check Task Status on Task Scheduler
hosts: win
gather_facts: false
tasks:
- name: Run the BAT file
win_shell: |
.\agentupdate.bat
args:
chdir: C:\ApplicareSingleAgentWindows\agentscripts
become: yes
become_user: <UserName>
become_method: runas
Update the following values in the file.
<UserName> = Machine Username (Ensure the account has administrative privileges on the Windows machine.)
Step 2: Run the following command from the same directory where host.yml is located.
ansible-playbook -i host.yml update_agent.yml
Comments
0 comments
Article is closed for comments.