#!/usr/bin/python --> #!/usr/bin/python2.6
2、安装过程:
1.安装setuptools模块安装
[root@localhost ~]# tar zxf setuptools-25.1.6.tar.gz
[root@localhost ~]# cd setuptools-25.1.6
[root@localhost setuptools-25.1.6]# python setup.py install
2.安装
pycrypto模块:
[root@localhost ~]# tar zxf pycrypto-2.6.1.tar.gz
[root@localhost ~]# cd pycrypto-2.6.1
[root@localhost pycrypto-2.6.1]# python setup.py install
3.安装PyYAML模块
[root@localhost ~]# tar zxf PyYAML-3.11.tar.gz
[root@localhost ~]# cd PyYAML-3.11
[root@localhost PyYAML-3.11]# python setup.py install
......
build/temp.linux-x86_64-2.7/check_libyaml.c:2:18: error: yaml.h: No such file or directory
build/temp.linux-x86_64-2.7/check_libyaml.c: In function ‘main’:
build/temp.linux-x86_64-2.7/check_libyaml.c:5: error: ‘yaml_parser_t’ undeclared (first use in this function)
build/temp.linux-x86_64-2.7/check_libyaml.c:5: error: (Each undeclared identifier is reported only once
build/temp.linux-x86_64-2.7/check_libyaml.c:5: error: for each function it appears in.)
build/temp.linux-x86_64-2.7/check_libyaml.c:5: error: expected ‘;’ before ‘parser’
.............
由于报错,因此先安装yaml 模块
[root@localhost ~]# tar zxf yaml-0.1.5.tar.gz
[root@localhost ~]# cd yaml-0.1.5
[root@localhost yaml-0.1.5]# ./configure --prefix=/usr/local/
[root@localhost yaml-0.1.5]# make && make install
继续安装
[root@localhost ~]# cd PyYAML-3.11
[root@localhost PyYAML-3.11]# python setup.py install
4.安装Jinja2模块
[root@localhost ~]# tar zxf Jinja2-2.8.tar.gz
[root@localhost ~]# cd Jinja2-2.8
[root@localhost Jinja2-2.8]# python setup.py install
5.安装paramiko模块
[root@localhost ~]# tar zxf paramiko-2.0.2.tar.gz
[root@localhost ~]# cd paramiko-2.0.2
[root@localhost paramiko-2.0.2]# python setup.py install
6.安装simplejson模块
[root@localhost ~]# tar zxf simplejson-3.8.2.tar.gz
[root@localhost ~]# cd simplejson-3.8.2
[root@localhost simplejson-3.8.2]# python setup.py install
7.安装ansible模块
[root@localhost ~]# tar xf v1.7.2
[root@localhost ~]# cd ansible-1.7.2/
[root@localhost ansible-1.7.2]# python setup.py install
至此安装已经完成了,此次安装比较顺利
我第一次安装的时候,出现了好多的包依赖,下面是我第一次安装过程当中所用的包地址:
3、ansible的基本使用
ansible <pattern_hosts> -m <module_name> -a <arguments>
1.远程命令模块
command //远程执行shell命令
scripts //scp + shell
shell //执行远程主机的shell脚本
eg:
ansible webserver -m command -a "uptime"
2.copy模块
ansible webserver -m copy -a "src= dest= owner= group= mode= "
3.stat模块
4.get_url
5.yum模块
ansible webserver -m yum -a "name= state= "
ansible webserver -m apt -a "name= state= "
6.cron
ansible webserver -m cron -a "name='check dirs' hour='5.2' job='ls -alh > /dev/null'"
7.mount
ansible webserver -m mount -a "name=/mnt src=/dev/sdb fstype=ext4 opts=ro state=present"
8.service
ansible webserver -m service -a "name=httpd state=stopped"
9.sysctl
10.user
ansible webserver -m user -a "name=dayuan comment='dayuanhello'" //添加用户
ansible webserver -m user -a "name=dayuan state=absent removes=yes" //删除用户