From 3fdcaa34650072a0ae53af7c3fc6682aedbd75b3 Mon Sep 17 00:00:00 2001 From: Alex Kup <116945542+Lifailon@users.noreply.github.com> Date: Fri, 28 Jul 2023 02:31:16 +0300 Subject: [PATCH] add ansible, winrm config, bit convertor, openssh, hyper-v, pki add ansible modules --- posh.txt | 128 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 117 insertions(+), 11 deletions(-) diff --git a/posh.txt b/posh.txt index 2ecb17c..dc3ba9c 100644 --- a/posh.txt +++ b/posh.txt @@ -271,8 +271,8 @@ pwsh -NoExit -ExecutionPolicy Unrestricted -WindowStyle Maximized -File "$(FULL_ Parsing text to Markdown: -Macros: Fn<+`+Fn>+Fn>+`+> -Replace: "# " -> "`" +Macros: FnLeft+'+FnRight+FnRight+\s\\+Down +Replace: "# ","'" . # Обозначает любой символ \ # Экранирующий символ. Символы которые экранируются: ^, [, ., $, {, *, (, ), \, +, |, ?, <, > @@ -303,7 +303,7 @@ $ # Конец строки \d{2,4} # Найти две или четыре {4,} # Найти четыре и более -^\s{0,}#.+ +^\s{1,}#.+ # поиск вначале строки комментария и пробел после него 1 или больше и любое кол-во символов # Regex @@ -476,7 +476,7 @@ fun-switch -param # Bit -Двоичная Десятичная +Двоичное Десятичное 1 1 10 2 11 3 @@ -494,7 +494,7 @@ fun-switch -param 1111 15 1 0000 16 -Двоичное Десятичное Номер разряда +Двоичное Десятичное Номер разряда 1 1 0 10 2 1 100 4 2 @@ -1751,7 +1751,7 @@ Get-NetAdapter "vEthernet (NAT)" | New-NetIPAddress -IPAddress 192.168.3.200 -Ad Add-NetNatStaticMapping -NatName LocalNat -Protocol TCP -ExternalIPAddress 0.0.0.0 -ExternalPort 2222 -InternalIPAddress 192.168.3.103 -InternalPort 2121 # проброс, вест трафик который приходит на хост Hyper-V TCP/2222, будет перенаправляться на соответствующий порт виртуальной машины за NAT. (Get-NetAdapter | where Name -match NAT).Status -Get-NetNatStaticMapping # отобразить пробросы +Get-NetNatStaticMapping # отобразить пробросы (NAT) Get-NetNat # список сетей Remove-NetNatStaticMapping -StaticMappingID 0 # удалить проброс Remove-NetNat -Name LocalNat # удалить сеть @@ -4679,6 +4679,8 @@ ansible us -a "cat /root/test.sh" -b ansible-doc -l | grep win_ # список всех модулей Windows (https://docs.ansible.com/ansible/latest/collections/ansible/windows/) ansible ws -m win_ping # windows модуль ansible ws -m win_ping -u WinRM-Writer # указать логин +ansible ws -m setup # собрать подробную информацию о системе +ansible ws -m win_whoami # информация о правах доступах, группах доступа ansible ws -m win_shell -a '$PSVersionTable' ansible ws -m win_shell -a 'Get-Service | where name -match "ssh|winrm"' ansible ws -m win_service -a "name=sshd state=stopped" @@ -4728,7 +4730,7 @@ ansible-playbook /etc/ansible/powershell-param.yml ### win_chocolatey -nano /etc/ansible/setup-chocolatey.yml +nano /etc/ansible/setup-adobe-acrobat.yml - hosts: ws tasks: @@ -4737,9 +4739,9 @@ nano /etc/ansible/setup-chocolatey.yml name: adobereader state: present -ansible-playbook /etc/ansible/setup-chocolatey.yml +ansible-playbook /etc/ansible/setup-adobe-acrobat.yml -nano /etc/ansible/setup-chocolatey.yml +nano /etc/ansible/setup-openssh.yml - hosts: ws tasks: @@ -4749,7 +4751,7 @@ nano /etc/ansible/setup-chocolatey.yml package_params: /SSHServerFeature state: present -ansible-playbook /etc/ansible/setup-chocolatey.yml +ansible-playbook /etc/ansible/setup-openssh.yml ### win_regedit @@ -4766,7 +4768,60 @@ nano /etc/ansible/win-set-shell-ssh-ps7.yml type: string state: present -ansible-playbook /etc/ansible/win-set-shell-ssh-ps7.yml -i /etc/ansible/hosts +ansible-playbook /etc/ansible/win-set-shell-ssh-ps7.yml + +### win_service + +nano /etc/ansible/win-service.yml + +- hosts: ws + tasks: + - name: Start service + win_service: + name: sshd + state: started +# state: stopped +# state: restarted +# start_mode: auto + +ansible-playbook /etc/ansible/win-service.yml + +### win_service_info + +nano /etc/ansible/get-service.yml + +- hosts: ws + tasks: + - name: Get info for a single service + win_service_info: + name: sshd + register: service_info + - name: Print returned information + ansible.builtin.debug: + var: service_info.services + +ansible-playbook /etc/ansible/get-service.yml + +### fetch/slurp + +nano /etc/ansible/copy-from-win-to-local.yml + +- hosts: ws + tasks: + - name: Retrieve remote file on a Windows host +# Скопировать файл из Windows-системы + ansible.builtin.fetch: +# Прочитать файл (передать в память в формате Base64) +# ansible.builtin.slurp: + src: C:\Telegraf\telegraf.conf + dest: /root/telegraf.conf + flat: yes + register: telegraf_conf + - name: Print returned information + ansible.builtin.debug: + msg: "{{ telegraf_conf['content'] | b64decode }}" + +ansible-playbook /etc/ansible/copy-from-win-to-local.yml ### win_copy @@ -4869,6 +4924,33 @@ nano /etc/ansible/add-user-to-group.yml ansible-playbook /etc/ansible/add-user-to-group.yml +### win_user + +nano /etc/ansible/creat-win-user.yml + +- hosts: ws + tasks: + - name: Creat user + win_user: + name: test + password: 123098 + state: present + groups: + - deploy + +ansible-playbook /etc/ansible/creat-win-user.yml + +nano /etc/ansible/delete-win-user.yml + +- hosts: ws + tasks: + - name: Delete user + ansible.windows.win_user: + name: test + state: absent + +ansible-playbook /etc/ansible/delete-win-user.yml + ### win_feature nano /etc/ansible/install-feature.yml @@ -4894,6 +4976,30 @@ nano /etc/ansible/win-reboot.yml ansible-playbook /etc/ansible/win-reboot.yml +### win_find + +nano /etc/ansible/win-ls.yml + +- hosts: ws + tasks: + - name: Find files in multiple paths + ansible.windows.win_find: + paths: + - D:\Install\OpenSource + patterns: ['*.rar','*.zip','*.msi'] + # Файл созданный менее 7 дней назад + age: -7d + # Размер файла больше 10MB + size: 10485760 + # Рекурсивный поиск (в дочерних директориях) + recurse: true + register: command_output + - name: Output port ssh + debug: + var: command_output + +ansible-playbook /etc/ansible/win-ls.yml + # Jenkins nano /etc/apt/sources.list.d/jenkins.list