从Ansible运行powershell脚本

从Ansible运行powershell脚本

本文介绍了从Ansible运行powershell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个powershell脚本,该脚本接受文件ex.-"C:\ temp \ foo.ps1"的多个用户输入,然后运行.我正在尝试使用win_shell模块将该脚本与Ansible集成.如何传递Powershell脚本的用户输入:-

I have a powershell script which takes multiple user inputs for file ex.- "C:\temp\foo.ps1", then it runs. I am trying to integrate that script with Ansible using win_shell module. How can I pass the user inputs for the powershell script :-

  - name: windows test command
    win_shell: C:\temp\Snapshots.ps1
    args:
     stdin: C:\temp\test3.csv

脚本(powershell):-

Script(powershell):-

$CONumber = Read-Host "Enter the CO Number"

所以这需要用户输入,如何使用vars_prompt变量编辑它?

SO this takes input from user, how can I edit this using vars_prompt variable?

推荐答案

要传递test3.csv的内容作为脚本的输入,以下是一种方法:

To pass the content of your test3.csv as an input for your script, here is a way to do that :

- name: windows test command
  win_shell: C:\temp\Snapshots.ps1
  args:
    stdin: "{{ lookup('file', C:\temp\test3.csv) }}"

要将提示的vars内容从剧本传递给用户,您可以这样做:

To pass the content of vars prompted to the user from the playbook, you can do like this :

#playbook_snapshot.yml
- hosts: "my_host"
  gather_facts: no
  vars_prompt:
    # co_number will be set to user input, and available in your role
    - name: co_number
      prompt: "Enter the CO Number"
    - name: other_value
      prompt: "Enter what is needed"
  role:
    - { role: wintest }

#role wintest
- name: windows test command
  win_shell: C:\temp\Snapshots.ps1
  args:
    stdin: "{{ co_number}}\n
      {{ other_value }}"

这篇关于从Ansible运行powershell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 14:34