Skip to content

Instantly share code, notes, and snippets.

@fabiocruzcoelho
Last active March 19, 2018 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiocruzcoelho/ef259857e6b056aaa8ada4f015e4e2ad to your computer and use it in GitHub Desktop.
Save fabiocruzcoelho/ef259857e6b056aaa8ada4f015e4e2ad to your computer and use it in GitHub Desktop.
Passos para controlar windows server via ansible - Passos executados no windows server
PS > mkdir C:\work
PS > cd C:\work
PS > Invoke-WebRequest -Uri \
https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1 \
-OutFile ConfigureRemotingForAnsible.ps1
PS > powershell -ExecutionPolicy RemoteSigned .\ConfigureRemotingForAnsible.ps1 -SkipNetworkProfileCheck
Passos executados no Linux
# curl -sL https://bootstrap.pypa.io/get-pip.py | python
# pip install pywinrm

Criar o arquivo windows.yml em group_vars com o dados de conexção

ansible_user: 'useradmlocal'
ansible_password: 'passoword'
ansible_port: 5985
ansible_connection: 'winrm'
ansible_winrm_server_cert_validation: 'ignore'

Comando para teste

ansible windows -i hosts -m win_ping -vvvv

Criptografano senha via ansible-vault

ansible-vault encrypt windows.yml

Gerando arquivo com a senha criptografada

# echo 'my_vault_password' > ~/.vault_win_pass

Comando extras

winrm set winrm/config/service '@{AllowUnencrypted="true"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="2048"}'
winrm set winrm/config '@{MaxEnvelopeSizekb="4294967295"}'
winrm set winrm/config '@{MaxTimeoutms = "4294967295"}'
winrm set winrm/config '@{MaxBatchItems="4294967295"}'
winrm set winrm/config/Service '@{MaxConcurrentOperations="4294967295"}'
winrm set winrm/config/Service '@{MaxConcurrentOperationsPerUser="4294967295"}'
winrm set winrm/config/service '@{EnumerationTimeoutms ="4294967295"}'
winrm set winrm/config/service '@{MaxConnections ="50"}'
winrm set winrm/config/service '@{MaxPacketRetrievalTimeSeconds ="4294967295"}'
winrm set winrm/config/service/auth '@{CredSSP="True"}'
winrm set winrm/config/client '@{TrustedHosts="*"}'
winrm set winrm/config/client '@{NetworkDelayms="4294967295"}'
winrm set winrm/config/winrs '@{IdleTimeout ="2147483647"}'
winrm set winrm/config/winrs '@{MaxConcurrentUsers ="100"}'
winrm set winrm/config/winrs '@{MaxShellRunTime ="2147483647"}'
winrm set winrm/config/winrs '@{MaxProcessesPerShell ="5000"}'
winrm set winrm/config/winrs '@{MaxShellsPerUser ="5000"}'
winrm set winrm/config/winrs '@{AllowRemoteShellAccess="True"}'
winrm set winrm/config/winrs '@{MaxMemoryPerShellMB="2048"}'
Stop/Start WinRM
net stop winrm 
net start winrm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment