2
我想根據用戶在Ansible手冊中的輸入選擇一個特定的變量。具體而言,我想要求在服務器的某個位置上進行用戶輸入,然後根據輸入執行特定操作。Ansible - 使用用戶輸入來選擇一個變量
這是當前ansible劇本:在運行劇本時
- hosts: all
remote_user: root
gather_facts: True
vars:
loc1: "10.13.1.140"
loc2: "10.13.1.141"
loc3: "10.13.1.142"
vars_prompt:
- name: location
prompt: "Location of server? Input options: loc1/loc2/loc3"
private: no
tasks:
- name: Test connectivity to user selected location
wait_for: host={{ vars.location }} port=9999 delay=0 timeout=10 state=started
輸出:
[[email protected] cfengine]# ansible-playbook testpoo.yaml -i /tmp/test
SSH password:
Location of server? Input options: loc1/loc2/loc3: loc2
PLAY ***************************************************************************
TASK [setup] *******************************************************************
ok: [hostname.domain.com]
TASK [Test connectivity to user selected location] *****************************
fatal: [hostname.domain.com]: FAILED! => {"changed": false, "elapsed": 10, "failed": true, "msg": "Timeout when waiting for loc2:9999"}
PLAY RECAP *********************************************************************
hostname.domain.com : ok=1 changed=0 unreachable=0 failed=1
我想知道如何或者最好的方式來讀取到的鏈接的用戶輸入具有在變量部分頂部定義的位置的實際值(IP地址)的位置。可能是評價還是別的?
它的工作就像一個魅力。謝謝您的幫助!!! – nickyt4free