2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Playbook実行時に変数の入力をさせるvars_prompt

Last updated at Posted at 2017-12-03

AnsibleのPlaybookを作成して実行していると実行前になんらかの変数を入力させたいことがあります。vars_promptを使うと実現できます。

playbook.yml
- name: Test
  hosts: localhost
  vars_prompt:
    - name: "input_var"
      prompt: "INPUT: "
      confirm: no
      private: no
      default: "fish"
  tasks:
    - debug: msg="{{ input_var }}"

beefを指定してみます。

$ .venv/bin/ansible-playbook playbook.yml
 [WARNING]: Host file not found: /etc/ansible/hosts

 [WARNING]: provided hosts list is empty, only localhost is available

INPUT:  [fish]: beef
 _____________
< PLAY [Test] >
 -------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/                ||----w |
                ||     ||

 ______________
< TASK [setup] >
 --------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/                ||----w |
                ||     ||

ok: [localhost]
 ______________
< TASK [debug] >
 --------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/                ||----w |
                ||     ||

ok: [localhost] => {
    "msg": "beef"
}
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/                ||----w |
                ||     ||

localhost                  : ok=2    changed=0    unreachable=0    failed=0

指定せずにENTERを押すとデフォルト値が使われます。

$ .venv/bin/ansible-playbook playbook.yml
 [WARNING]: Host file not found: /etc/ansible/hosts

 [WARNING]: provided hosts list is empty, only localhost is available

INPUT:  [fish]:
 _____________
< PLAY [Test] >
 -------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/                ||----w |
                ||     ||

 ______________
< TASK [setup] >
 --------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/                ||----w |
                ||     ||

ok: [localhost]
 ______________
< TASK [debug] >
 --------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/                ||----w |
                ||     ||

ok: [localhost] => {
    "msg": "fish"
}
 ____________
< PLAY RECAP >
 ------------
        \   ^__^
         \  (oo)\_______
            (__)\       )\/                ||----w |
                ||     ||

localhost                  : ok=2    changed=0    unreachable=0    failed=0
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?