English 中文(简体)
如果在导入- playbook 中存在变量, 如何跳过 vars_ prompt?
原标题:How to skip vars_prompt if variables exist within import_playbook?

我有这个剧本 执行一些基本任务 在开关和防火墙上。

父母 :

- hosts: localhost
  become: no
  gather_facts: no

  vars_prompt:
    - name: ansible_user
      prompt: "Enter Username"
      private: no
    - name: ansible_password
      prompt: "Enter Password"
      private: yes

- name: Execute Script on Switch
  import_playbook: test_dummy_switch.yml

- name: Execute Script on Firewall
  import_playbook: test_dummy_fw.yml

Child 1 / 开关: 测试_ dommy_ coreit.yml

- hosts: Switch
  become: no
  gather_facts: no
  
  vars_prompt:
    - name: ansible_user
      prompt: "Enter Username"
      private: no
    - name: ansible_password
      prompt: "Enter Password"
      private: yes
  
  tasks:
    - name: Interface Config
      ios_config:
        lines:
          - description Testing Switch
        parents: "interface Gi0/0"  
      register: print_output

    - debug: var=print_output

儿童 2 / 防火墙: 测试_ dummy_ fw.yml

- hosts: Firewall
  become: no
  gather_facts: no
  
  vars_prompt:
    - name: ansible_user
      prompt: "Enter Username"
      private: no
    - name: ansible_password
      prompt: "Enter Password"
      private: yes
  
  tasks:
    - name: Interface Config
      ios_config:
        lines:
          - description Testing Firewall
        parents: "interface Ethernet1"  
      register: print_output

    - debug: var=print_output

我想创建一个脚本, 以在父游戏本中设置变量时跳过提示 。 我也在游戏本中尝试过这一点, 但是 Assible 仍然提示着儿童游戏本中的变量 。

父母 :

- hosts: localhost
  become: no
  gather_facts: no

  vars_prompt:
    - name: ansible_user
      prompt: "Enter Username"
      private: no
    - name: ansible_password
      prompt: "Enter Password"
      private: yes

  tasks:
  - set_fact:
      ansible_user: "{{ ansible_user }}"
      ansible_password: "{{ ansible_password }}"

- name: Execute Script on Switch
  import_playbook: test_dummy_switch.yml
  vars:
    ansible_user: "{{ ansible_user|d( default ) }}"
    ansible_password: "{{ ansible_password|d( default ) }}"
        
- name: Execute Script on Firewall
  import_playbook: test_dummy_fw.yml
  vars:
    ansible_user: "{{ ansible_user|d( default ) }}"
    ansible_password: "{{ ansible_password|d( default ) }}"

是否有办法可以确保不使用额外的变量 < / 强'来确认变量已经存在并跳过快速的 < 强 >? 因为仅需要此脚本的要求就可一次提示用户名和密码 。

问题回答

例如:

shell> cat pb1.yml
- hosts: localhost

  vars_prompt:

    - name: ansible_user
      prompt: Enter Username
      private: false
    - name: ansible_password
      prompt: Enter Password
      private: true

  tasks:

    - set_fact:
        ansible_user: "{{ ansible_user }}"
        ansible_password: "{{ ansible_password }}"

- import_playbook: pb2.yml
- import_playbook: pb3.yml
shell> cat pb2.yml
- hosts: localhost

  pre_tasks:

    - when: ansible_user|length == 0
      block:
        - pause:
            prompt: Enter Username
          register: out
        - set_fact:
            ansible_user: "{{ out.user_input }}"

    - when: ansible_password|length == 0
      block:
        - pause:
            prompt: Enter Password
            echo: false
          register: out
        - set_fact:
            ansible_password: "{{ out.user_input }}"

  tasks:

    - debug:
        msg: |
          ansible_user: {{ ansible_user }}
          ansible_password: {{ ansible_password }}




相关问题
Switching a view

I have a problem with switching views in an iPhone application. I have the source code of "Beginning iPhone 3 Development" (http://books.google.com/books?id=TcP2bgESYfgC&printsec=frontcover&dq=...

Issue with C function returning a gchar**

I have a function defined as the following (in C): gchar **Scan_Return_File_Tag_Field_From_Mask_Code (File_Tag *FileTag, gchar code) { switch (code) { case t : /* Title */ ...

PHP CASE statement not working with ZERO values

I don t understand what s happening here. Logically, it doesn t make any sense to me. <?php $level = 0; switch ($level) { case $level > 80: $answer = high ; break; case $level > 60: $...

c# switch statement question

I ll cut to the chase. I have two questions about switch that are simple, but I can t figure them out. First: in c# switch statements, do case statements have to be consecutive (with ints)? For ...

How can I use goto in a switch statement in Objective-C?

In my code I need to be able to jump (goto) a different case within the same switch statement. Is there a way to do this? My code is something like this: (There is a lot of code I just left it all ...

Which is faster - if..else or Select..case?

I have three condition to compare. Which one is more faster between the following two? Please point me out. Thanks all! If var = 1 then Command for updating database ElseIf var = 2 then ...

热门标签