#!/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" //刪除用戶