(.venv) root@da0fa5dd7aae:~/mycelery# cat hosts
[local]
127.0.0.1
[remote]
220.70.63.15
125.141.117.130
175.198.82.75
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts --connection=local local -m ping
127.0.0.1 | SUCCESS => {
"changed": false,
"ping": "pong"
}
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts --connection=local remote -m ping
125.141.117.130 | SUCCESS => {
"changed": false,
"ping": "pong"
}
220.70.63.15 | SUCCESS => {
"changed": false,
"ping": "pong"
}
175.198.82.75 | SUCCESS => {
"changed": false,
"ping": "pong"
}
ssh 키 교환이 안된 경우.
I believe you can use sshpass.
Ubuntu/Debian: apt-get install sshpass
Fedora/CentOS: yum install sshpass
For example:
sshpass -p "PASSWORD" ssh-copy-id -o StrictHostKeyChecking=no USERNAME@IP
각 시스템 마다 등록을 해 주자.
(.venv) root@da0fa5dd7aae:~/mycelery# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:C0KJWX/Z2ljuskW3WHaK3Q6xxjYpgXRSTp6BLmAcD9c root@da0fa5dd7aae
The key's randomart image is:
+---[RSA 2048]----+
| .+... .+ |
| ++* EB o |
| o.o.o.= B |
| . .o.X |
| . ..S = = . |
| . . + X O |
| o * % . |
| + + + |
| . . |
+----[SHA256]-----+
(.venv) root@da0fa5dd7aae:~/mycelery# ssh-copy-id 175.198.82.75
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@175.198.82.75's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '175.198.82.75'"
and check to make sure that only the key(s) you wanted were added.
(.venv) root@da0fa5dd7aae:~/mycelery# cat hosts
[local]
127.0.0.1
[remote]
220.70.63.15
125.141.117.130
175.198.82.75
(.venv) root@da0fa5dd7aae:~/mycelery# ssh-copy-id 125.141.117.130
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '125.141.117.130 (125.141.117.130)' can't be established.
RSA key fingerprint is SHA256:OaLdygTqtdebAkUMUOnE8Y+MCTBIpxsI88n/puhV778.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@125.141.117.130's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '125.141.117.130'"
and check to make sure that only the key(s) you wanted were added.
(.venv) root@da0fa5dd7aae:~/mycelery# ssh-copy-id 220.70.63.15
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
root@220.70.63.15's password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '220.70.63.15'"
and check to make sure that only the key(s) you wanted were added.
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts remote -m ping
175.198.82.75 | SUCCESS => {
"changed": false,
"ping": "pong"
}
125.141.117.130 | SUCCESS => {
"changed": false,
"ping": "pong"
}
220.70.63.15 | SUCCESS => {
"changed": false,
"ping": "pong"
}
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts remote -m shell -a 'rpm -qa | grep ssh'
[WARNING]: Consider using the yum, dnf or zypper module rather than running
rpm. If you need to use command because yum, dnf or zypper is insufficient you
can add warn=False to this command task or set command_warnings=False in
ansible.cfg to get rid of this message.
125.141.117.130 | CHANGED | rc=0 >>
libssh2-1.4.2-1.el6_6.1.x86_64
openssh-5.3p1-123.el6_9.x86_64
openssh-clients-5.3p1-123.el6_9.x86_64
openssh-server-5.3p1-123.el6_9.x86_64
175.198.82.75 | CHANGED | rc=0 >>
openssh-server-5.3p1-123.el6_9.x86_64
openssh-askpass-5.3p1-123.el6_9.x86_64
openssh-clients-5.3p1-123.el6_9.x86_64
libssh2-1.4.2-1.el6_6.1.x86_64
openssh-5.3p1-123.el6_9.x86_64
openssh-ldap-5.3p1-123.el6_9.x86_64
220.70.63.15 | CHANGED | rc=0 >>
libssh2-1.4.2-1.el6_6.1.x86_64
openssh-5.3p1-111.el6.x86_64
openssh-clients-5.3p1-111.el6.x86_64
openssh-server-5.3p1-111.el6.x86_64
본 서버에서 실행해도 안 나오는 메시지가 출력된다.
[root@ibm ~]# rpm -qa | grep ssh
libssh2-1.4.2-1.el6_6.1.x86_64
openssh-5.3p1-111.el6.x86_64
openssh-clients-5.3p1-111.el6.x86_64
openssh-server-5.3p1-111.el6.x86_64
[root@ibm ~]#
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts remote -m apt -a 'name=openssh-server state=installed update_cache=true'
175.198.82.75 | FAILED! => {
"changed": false,
"cmd": "apt-get update",
"msg": "[Errno 2] 그런 파일이나 디렉터리가 없습니다",
"rc": 2
}
125.141.117.130 | FAILED! => {
"changed": false,
"cmd": "apt-get update",
"msg": "[Errno 2] 그런 파일이나 디렉터리가 없습니다",
"rc": 2
}
220.70.63.15 | FAILED! => {
"changed": false,
"cmd": "apt-get update",
"msg": "[Errno 2] 그런 파일이나 디렉터리가 없습니다",
"rc": 2
}
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts remote -m shell -a 'rpm -qa | grep ssh'
[WARNING]: Consider using the yum, dnf or zypper module rather than running
rpm. If you need to use command because yum, dnf or zypper is insufficient you
can add warn=False to this command task or set command_warnings=False in
ansible.cfg to get rid of this message.
175.198.82.75 | CHANGED | rc=0 >>
openssh-server-5.3p1-123.el6_9.x86_64
openssh-askpass-5.3p1-123.el6_9.x86_64
openssh-clients-5.3p1-123.el6_9.x86_64
libssh2-1.4.2-1.el6_6.1.x86_64
openssh-5.3p1-123.el6_9.x86_64
openssh-ldap-5.3p1-123.el6_9.x86_64
125.141.117.130 | CHANGED | rc=0 >>
libssh2-1.4.2-1.el6_6.1.x86_64
openssh-5.3p1-123.el6_9.x86_64
openssh-clients-5.3p1-123.el6_9.x86_64
openssh-server-5.3p1-123.el6_9.x86_64
220.70.63.15 | CHANGED | rc=0 >>
libssh2-1.4.2-1.el6_6.1.x86_64
openssh-5.3p1-111.el6.x86_64
openssh-clients-5.3p1-111.el6.x86_64
openssh-server-5.3p1-111.el6.x86_64
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts remote -m shell -a '/opt/MegaRAID/storcli/storcli64 /call /eall /sall show | grep HDD'
175.198.82.75 | FAILED | rc=1 >>
/bin/sh: /opt/MegaRAID/storcli/storcli64: 그런 파일이나 디렉터리가 없습니다non-zero return code
125.141.117.130 | FAILED | rc=1 >>
/bin/sh: /opt/MegaRAID/storcli/storcli64: 그런 파일이나 디렉터리가 없습니다non-zero return code
220.70.63.15 | CHANGED | rc=0 >>
252:0 25 Onln 0 135.972 GB SAS HDD N N 512B MBE2147RC U -
252:1 22 Onln 0 135.972 GB SAS HDD N N 512B ST9146852SS U -
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts remote -m shell -a 'ssacli controller all show'
175.198.82.75 | FAILED | rc=127 >>
/bin/sh: ssacli: command not foundnon-zero return code
220.70.63.15 | FAILED | rc=127 >>
/bin/sh: ssacli: command not foundnon-zero return code
125.141.117.130 | CHANGED | rc=0 >>
Smart Array P400 in Slot 1 (sn: P61620H9SVY22G)
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts remote -m shell -a 'ssacli controller slot=1 physicaldrive all show status'
175.198.82.75 | FAILED | rc=127 >>
/bin/sh: ssacli: command not foundnon-zero return code
220.70.63.15 | FAILED | rc=127 >>
/bin/sh: ssacli: command not foundnon-zero return code
125.141.117.130 | CHANGED | rc=0 >>
physicaldrive 2I:1:1 (port 2I:box 1:bay 1, 146 GB): OK
physicaldrive 2I:1:2 (port 2I:box 1:bay 2, 146 GB): OK
(.venv) root@da0fa5dd7aae:~/mycelery# ansible -i ./hosts remote -m shell -a '/opt/MegaRAID/storcli/storcli64 /c0 show | grep HDD'
175.198.82.75 | FAILED | rc=1 >>
/bin/sh: /opt/MegaRAID/storcli/storcli64: 그런 파일이나 디렉터리가 없습니다non-zero return code
125.141.117.130 | FAILED | rc=1 >>
/bin/sh: /opt/MegaRAID/storcli/storcli64: 그런 파일이나 디렉터리가 없습니다non-zero return code
220.70.63.15 | CHANGED | rc=0 >>
252:0 25 Onln 0 135.972 GB SAS HDD N N 512B MBE2147RC U -
252:1 22 Onln 0 135.972 GB SAS HDD N N 512B ST9146852SS U -