playbook 之 vars_prompt

示例1

- hosts: 127.0.0.1
  vars_prompt:
  - name: host
    prompt: "please input your hostip"
  - name: port 
    prompt: "please input your port"
  tasks:
  - name: debug
    debug:
      msg: "http://{{ host }}:{{ port }} "

示例2

private默认为true 隐藏用户输入

- hosts: 127.0.0.1
  vars_prompt:
  - name: host
    prompt: "please input your hostip"
    private: no
  - name: port 
    prompt: "please input your port"
    private: no
  tasks:
  - name: debug
    debug:
      msg: "http://{{ host }}:{{ port }} "

示例3

default 定义默认值

- hosts: 127.0.0.1
  vars_prompt:
  - name: host
    prompt: "please input your hostip"
    private: no
    default: 127.0.0.1
  - name: port 
    prompt: "please input your port"
    private: no
    default: 80
  tasks:
  - name: debug
    debug:
      msg: "http://{{ host }}:{{ port }} "

示例4

confirm要求用户再次输入

- hosts: 127.0.0.1
  vars_prompt:
  - name: host
    prompt: "please input your hostip"
    private: no
    default: 127.0.0.1
  - name: port 
    prompt: "please input your port"
    private: no
    default: 80
    confirm: yes
  tasks:
  - name: debug
    debug:
      msg: "http://{{ host }}:{{ port }} "
posted @ 2023-01-19 15:10  mingtian是吧  阅读(36)  评论(0编辑  收藏  举报