CentOS7安装ansible
时间:2015-02-15 22:57 来源:linux.it.net.cn 作者:IT
vi
/etc/sysconfig/network-scripts/ifcfg-eth0
NAME=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.16.4.243
GATEWAY=172.16.4.254
NETMASK=255.255.255.0
DNS1=114.114.114.114
systemctl restart network
easy_install simplejson
easy_install pip
yum
install
gcc python-devel
easy_install ansible
pip list
vi
/etc/ssh/ssh_config
StrictHostKeyChecking no
systemctl reload sshd
ssh
-keygen -t rsa
ssh
-copy-
id
-i ~/.
ssh
/id_rsa
.pub root@172.16.4.247
vi
~
/hosts
172.16.4.247
ansible all -i ~
/hosts
-m
ping
ansible
'~.*247'
-i ~
/hosts
-m yum -a
'name=libselinux-python state=present'
ansible
'~.*247'
-i ~
/hosts
-m copy -a
'src=test.sh dest=/root'
ansible
'~.*247'
-i ~
/hosts
-a
'bash test.sh'
#!/usr/bin/python
import
ansible.runner
import
sys
# construct the ansible runner and execute on all hosts
results
=
ansible.runner.Runner(
host_list
=
'/root/hosts'
,
pattern
=
'*'
, forks
=
10
,
module_name
=
'command'
, module_args
=
'which systemctl'
,
).run()
if
results
is
None
:
print
"No hosts found"
sys.exit(
1
)
print
"\033[32mUP ***********\033[0m"
for
(hostname, result)
in
results[
'contacted'
].items():
if
not
'failed'
in
result:
if
len
(result[
'stdout'
]):
print
"%s >>>stdout: %s"
%
(hostname, result[
'stdout'
])
if
len
(result[
'stderr'
]):
print
"%s >>>stderr: %s"
%
(hostname, result[
'stderr'
])
print
"\033[31mFAILED *******\033[0m"
for
(hostname, result)
in
results[
'contacted'
].items():
if
'failed'
in
result:
print
"%s >>> %s"
%
(hostname, result[
'msg'
])
print
"\033[33mDOWN *********\033[0m"
for
(hostname, result)
in
results[
'dark'
].items():
print
"%s >>> %s"
%
(hostname, result)
(责任编辑:IT)
(责任编辑:IT) |