GAGA LIFE.

インフラエンジニアブログ

スポンサーリンク

ansibleコマンド実行

概要

環境とコントロール/ターゲットを整備したので、動作確認のためにコマンドを実行してみます。

コマンド実行

ここでは、playbookを使用せず、モジュールを直接指定するansibleコマンドを使用します。
まず、接続可能ターゲットの情報を記載したインベントを作成。
動作確認としてターゲットノードを用意しないでコントロールノードそのものをターゲットノードに指定しています。
./sec2/inventory/test01_inventory.ini

1 [test_servers]
2 localhost

動作確認

ping

$ cd PATH_TO/effective_ansible/sec2/
$ ansible -i inventory/test01_inventory.ini test_servers -m ping
localhost | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

「localhost | SUCCESS」の表示で接続成功を確認できます。 「"changed": false」は、実行コマンドで何の変更もなされていないためです。

file

「-a」:作成ファイル指定

$ cd PATH_TO/effective_ansible/sec2/
$ ansible -i inventory/test01_inventory.ini test_servers -m file -a 'path=/home/ansible/test.txt state=touch mode=0644'
localhost | SUCCESS => {
    "changed": true, 
    "dest": "/home/ansible/test.txt", 
    "gid": 1002, 
    "group": "ansible", 
    "mode": "0644", 
    "owner": "ansible", 
    "secontext": "unconfined_u:object_r:user_home_t:s0", 
    "size": 0, 
    "state": "file", 
    "uid": 1002
}
$ ls -la /home/ansible/test.txt 
-rw-r--r--. 1 ansible ansible 0  114 18:43 /home/ansible/test.txt

「"changed": true」で変更を確認でき、test.txtの空ファイル作成ができていることが確認できます。

スポンサーリンク