No one sees the real me

仮想化PF基盤SE

Ansible に触れる(初日)

全く無知ってのもあれなので完全未経験者がどんなものかっていう触りだけ
yum で ansible をインストールした後、公開鍵設定後、早速


[root@ansible_base work]# ls
createfile.yaml  hosts        shell1.yaml   test_01.py
hostall          remote.yaml  test_01.json
[root@ansible_base work]#
[root@ansible_base work]# cat hosts
[master]
192.168.249.104
[node]
192.168.249.105
[root@ansible_base work]#
[root@ansible_base work]# cat shell1.yaml
- hosts: node    #対象ホストを指定する。
  tasks:         #実行するtaskを指定する。
    - name: Execute the command in remote shell.
      shell: hostname
      register: result
    - debug:
        var: result
[root@ansible_base work]#
[root@ansible_base work]# ansible-playbook shell1.yaml -i hosts

PLAY [node] ********************************************************************

TASK [Gathering Facts] *********************************************************
ok: [192.168.249.105]

TASK [Execute the command in remote shell.] ************************************
changed: [192.168.249.105]

TASK [debug] *******************************************************************
ok: [192.168.249.105] => {
    "result": {
        "changed": true,
        "cmd": "hostname",
        "delta": "0:00:00.004091",
        "end": "2018-10-27 07:11:17.098956",
        "failed": false,
        "rc": 0,
        "start": "2018-10-27 07:11:17.094865",
        "stderr": "",
        "stderr_lines": [],
        "stdout": "remote",
        "stdout_lines": [
            "remote"
        ]
    }
}

PLAY RECAP *********************************************************************
192.168.249.105            : ok=3    changed=1    unreachable=0    failed=0

[root@ansible_base work]#


取り出したかったもの
"stdout": "remote",


実行と戻り値分岐は便利そう、ただのデータ取得には整形が大変そう(初日の感想)
調べてみる