ksaitoの日記

日々試したことの覚え書き

shellモジュールとdebugモジュール

移転しました。

自動的にリダイレクトします。

shellモジュールの実行結果をdebugモジュールで表示してみます。

ソース

使ったソースは下記の通りです。

$ cat site.yml 
---
- hosts: appservers
  tasks:
    - debug:
    - shell: ls
      register: result
      changed_when: False
    - debug: var="result.rc"
    - debug: var="result.stdout"
    - debug: var="result.stdout_lines"
$ 

実行

一つ目のdebugモジュールは、オプションを何も指定しないと"Hello, World!"を表示するんですね。

shellモジュールで実行したコマンドの終了ステータス、実行結果を表示します。

$ ansible-playbook -i hosts site.yml 

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [appserv1]

TASK [debug] *******************************************************************
ok: [appserv1] => {
    "msg": "Hello world!"
}

TASK [command] *****************************************************************
ok: [appserv1]

TASK [debug] *******************************************************************
ok: [appserv1] => {
    "result.rc": "0"
}

TASK [debug] *******************************************************************
ok: [appserv1] => {
    "result.stdout": "git\npub\nwork"
}

TASK [debug] *******************************************************************
ok: [appserv1] => {
    "result.stdout_lines": [
        "git", 
        "pub", 
        "work"
    ]
}

PLAY RECAP *********************************************************************
appserv1                   : ok=6    changed=0    unreachable=0    failed=0   

$