No one sees the real me

仮想化PF基盤SE

Ansible に触れる(専門外)


【鍵作成】
[ansible@ansible ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansible/.ssh/id_rsa):
Created directory '/home/ansible/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ansible/.ssh/id_rsa.
Your public key has been saved in /home/ansible/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:h8cD7fk0UEg+hyG4115mJur8KntpRIubYbKGosa7MOI ansible@ansible
The key's randomart image is:
+---[RSA 2048]----+
|       ...o..    |
|      .  +.+     |
|       ...* .    |
|      . o=o==    |
|       +S+B*o    |
|    . + +o.+ .   |
|=  . + B .  .    |
|=+. o + *        |
|+Eo.  .=.o.      |
+----[SHA256]-----+
[ansible@ansible ~]$
[ansible@ansible ~]$
[ansible@ansible ~]$


【インベントリファイル作成】
[ansible@ansible ~]$ cat target
[node]
192.168.249.110
192.168.249.111
192.168.249.112
[ansible@ansible ~]$


【公開鍵配布】

[ansible@ansible ~]$ for i in `cat target | grep -v node` ; do ssh-copy-id -o StrictHostKeyChecking=no -i $HOME/.ssh/id_rsa.pub $i ; done
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ansible/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ansible@192.168.249.110's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -o 'StrictHostKeyChecking=no' '192.168.249.110'"
and check to make sure that only the key(s) you wanted were added.

/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ansible/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ansible@192.168.249.111's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -o 'StrictHostKeyChecking=no' '192.168.249.111'"
and check to make sure that only the key(s) you wanted were added.

/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/ansible/.ssh/id_rsa.pub"
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
ansible@192.168.249.112's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh -o 'StrictHostKeyChecking=no' '192.168.249.112'"
and check to make sure that only the key(s) you wanted were added.

[ansible@ansible ~]$


【sshログイン確認】

[ansible@ansible ~]$ for i in `cat target | grep -v node` ; do ssh $i ; done
Last failed login: Sat Dec 22 02:54:22 JST 2018 from 192.168.249.106 on ssh:notty
There was 1 failed login attempt since the last successful login.
Last login: Sat Dec 22 00:40:12 2018
[ansible@target1 ~]$ exit
ログアウト
Connection to 192.168.249.110 closed.
Last login: Sat Dec 22 00:40:12 2018
[ansible@target2 ~]$ exit
ログアウト
Connection to 192.168.249.111 closed.
Last login: Sat Dec 22 00:40:12 2018
[ansible@target3 ~]$ exit
ログアウト
Connection to 192.168.249.112 closed.
[ansible@ansible ~]$
[ansible@ansible ~]$


【Playbook作成(ping)[ansible@ansible ~]$ cat ping_playbook.yaml
- hosts: node   # 対象ターゲットノードを指定する
  tasks:         #実行するtaskを指定する

        - name: ping check
          ping:

[ansible@ansible ~]$


【Playbookの実行】
[ansible@ansible ~]$ ansible-playbook ping_playbook.yaml -i target

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

TASK [Gathering Facts] *********************************************************************************
ok: [192.168.249.110]
ok: [192.168.249.112]
ok: [192.168.249.111]

TASK [ping check] **************************************************************************************
ok: [192.168.249.111]
ok: [192.168.249.110]
ok: [192.168.249.112]

PLAY RECAP *********************************************************************************************
192.168.249.110            : ok=2    changed=0    unreachable=0    failed=0
192.168.249.111            : ok=2    changed=0    unreachable=0    failed=0
192.168.249.112            : ok=2    changed=0    unreachable=0    failed=0

[ansible@ansible ~]$
[ansible@ansible ~]$