Run Repadmin on the Domain controller from ansible task server

177 views
Skip to first unread message

Nitrous

unread,
Dec 6, 2021, 12:22:04 PM12/6/21
to Ansible Project
I am trying to figure out, how to run repadmin on the Domain controller itself:

- name: Sync Active Directory With New Changes
      ansible.windows.win_shell: repadmin /syncall '{{ server.domain }}' /AdeP
      become: yes
      become_method: runas
      become_user: '{{ server.domain }}\username'

The above tries to run on the task server, that has the AD modules installed, but I would like to run the above on the domain
controller itself.

Would we use the delegate option and then specify the Domain controller? Thanks

Nitrous

unread,
Dec 6, 2021, 1:15:24 PM12/6/21
to Ansible Project
This works from the ansible task server using powershell:

$password = "xxx" | ConvertTo-SecureString -asPlainText -Force
$username = "xx\xxxxx"
$credential = New-Object System.Management.Automation.PSCredential($username,$password) 
Invoke-Command -ComputerName DC01 -credential $Credential -ScriptBlock { repadmin /syncall /AdeP }

How can I use the above to be able to use it using the ansible.windows.win_shell module, in ansible? Thanks

Nitrous

unread,
Dec 7, 2021, 11:40:02 AM12/7/21
to Ansible Project
I managed to figure out how to do this, if anyone is interested, used invoke-command:

- name: Sync Active Directory With New Changes
     ansible.windows.win_shell:
       Invoke-Command -ComputerName '{{ server.dc }}' -ScriptBlock { repadmin /syncall /AdeP }
     become: yes
     become_method: runas
     vars:
       ansible_become_user: '{{ server.domain }}\username of a domain admin account'
       ansible_become_password: '{{ ansible_password }}'
   become_user: "{{ server.domain }}\username of a domain admin account"
Reply all
Reply to author
Forward
0 new messages