PowerShell脚本、Ansible.note

noteId: WEB9107b5dabbe3cdc26a1dfb75d28b3339 · 原始路径:/ALL/世赛题目(练习) - 笔记/第48届/08-集训队解题/B/PowerShell脚本、Ansible.note · 图片:15 · 附件待处理:1

 
1、powershell:
 
新(CLT机器单独起一行,万一到时候DHCP地址变了,不是100,test-connection就会报错):
 
旧:
 
 
 
 
2、Ansible:
 
·连接:
模板:
grep -r winrm_server /usr/lib/python3
 
 
使用 win_file 模块创建一个目录进行幂等,创建文件无法进行幂等
 
1)P1.yaml:
---
- name: hostname
  hosts: all
  gather_facts: false
  tasks:
    - name: check
      win_file:
        path: c:\P1
        state: directory
      register: check
 
    - name: hostname
      win_shell: |
        netdom renamecomputer WIN-FBKCLPU0B85 /newname:Potwoman_B /force
      when: check.changed
 
    - name: reboot
      win_reboot:
        reboot_timeout: 300
      changed_when: false
      when: check.changed
 
 
 
2)P2.yaml:
需要是单引号,不能是双引号,否则 反引号会生效不会被当成字符串
 
---
- name: P2
  hosts: all
  gather_facts: no
 
  tasks:
    - name: Create 50 CMD shortcuts on Public Desktop
      community.windows.win_shortcut:
        src: C:\Windows\System32\cmd.exe
        dest: 'C:\Users\Public\Desktop\HEACKED_{{ item }}.lnk'
      with_sequence: start=1 end=50 format=%03d
 
 
2)P3.yaml:
 
 
 
4)P4.yaml: