编译安装:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
$ yum install libevent-devel gcc gcc-c++ libffi-devel openssl-devel openssl $ yum install zlib zlib-devel gcc gcc-c++ $ wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz $ tar zxf Python-3.6.5.tgz $ cd Python-3.6.5 $ ./configure --prefix=/opt/Python-3.6.5 --enable-optimizations && make && make install $ ln -s /opt/Python-3.6.5/ /usr/local/python3 $ cd /opt/ $ /usr/local/python3/bin/python3 -m venv py3 $ source /opt/py3/bin/activate $ cd /byrd/tools/ $ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py $ python get-pip.py $ wget https://releases.ansible.com/ansible/ansible-2.8.0.tar.gz $ #yum install python python-devel libevent-devel gcc gcc-c++ libffi-devel openssl-devel epel-release -y $ yum install python36-devel -y $ yum install patch readline-devel #readline $ tar zxf ansible-2.8.0.tar.gz $ cd ansible-2.8.0 $ python setup.py install |
基本运行:
1:检测存活
012345678910111213141516 $ ansible all -m ping -u byrd -b192.168.227.28 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"ping": "pong"}$ ansible web -m ping -u byrd -b192.168.227.28 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"ping": "pong"}
2:复制文件
012345678910111213141516171819202122232425262728293031323334353637 $ ansible web -m copy -a "src=/etc/fstab dest=/tmp/fstab owner=byrd group=byrd mode=644 backup=yes"192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"checksum": "daa6c89d3613142396f990d5a58f92f8853f1887","dest": "/tmp/fstab","gid": 2770,"group": "byrd","md5sum": "5715341fe9e21339a44a4338e9c10fca","mode": "0644","owner": "byrd","secontext": "unconfined_u:object_r:user_home_t:s0","size": 501,"src": "/home/byrd/.ansible/tmp/ansible-tmp-1560839869.9026308-57960705669078/source","state": "file","uid": 2770}$ ansible web -m copy -a "src=/etc/fstab dest=/tmp/fstab owner=root group=root mode=644 backup=yes" -u byrd -b192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"checksum": "daa6c89d3613142396f990d5a58f92f8853f1887","dest": "/tmp/fstab","gid": 0,"group": "root","mode": "0644","owner": "root","path": "/tmp/fstab","secontext": "unconfined_u:object_r:user_home_t:s0","size": 501,"state": "file","uid": 0}
3:列出主机
012 $ ansible web --listhosts (1):192.168.227.28
4:硬盘大小
012345678910111213141516171819202122 $ ansible web -a "df -h"192.168.227.28 | CHANGED | rc=0 >>Filesystem Size Used Avail Use% Mounted on/dev/sda3 798G 1.1G 797G 1% /devtmpfs 477M 0 477M 0% /devtmpfs 488M 0 488M 0% /dev/shmtmpfs 488M 7.7M 480M 2% /runtmpfs 488M 0 488M 0% /sys/fs/cgroup/dev/sda1 297M 107M 191M 36% /boottmpfs 98M 0 98M 0% /run/user/0tmpfs 98M 0 98M 0% /run/user/2770$ ansible web -m shell -a "df -h"192.168.227.28 | CHANGED | rc=0 >>Filesystem Size Used Avail Use% Mounted on/dev/sda3 798G 1.1G 797G 1% /devtmpfs 477M 0 477M 0% /devtmpfs 488M 0 488M 0% /dev/shmtmpfs 488M 7.7M 480M 2% /runtmpfs 488M 0 488M 0% /sys/fs/cgroup/dev/sda1 297M 107M 191M 36% /boottmpfs 98M 0 98M 0% /run/user/0tmpfs 98M 0 98M 0% /run/user/2770
5:yum安装
012345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 $ ansible web -m yum -a 'name=redhat-lsb state=present' -u byrd -b192.168.227.28 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"msg": "","rc": 0,"results": ["redhat-lsb-4.1-27.el7.centos.1.x86_64 providing redhat-lsb is already installed"]}$ ansible web -m yum -a "name=ntp state=present" -u byrd -b192.168.227.28 | SUCCESS => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"msg": "","rc": 0,"results": ["ntp-4.2.6p5-28.el7.centos.x86_64 providing ntp is already installed"]}$ ansible web -m yum -a "name=net-tools state=present" -u byrd -b$ ansible web -m service -a "name=ntpd state=started"192.168.227.28 | FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": false,"msg": "Unable to start service ntpd: Failed to start ntpd.service: Connection timed out\nSee system logs and 'systemctl status ntpd.service' for details.\n"}$ ansible web -m service -a "name=ntpd state=started" -u byrd -b192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"name": "ntpd","state": "started","status": {====略====}}$ ansible web -m service -a "name=ntpd state=started enable=yes" -u byrd -b
6:系统版本
0123456 $ ansible web -m command -a 'lsb_release -a'192.168.227.28 | CHANGED | rc=0 >>LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarchDistributor ID: CentOSDescription: CentOS Linux release 7.5.1804 (Core)Release: 7.5.1804Codename: Core
7:限定主机
012345678910111213141516171819202122232425262728293031 $ ansible web -m command -a "service ntpd status" --limit "192.168.227.28"[WARNING]: Consider using the service module rather than running 'service'. If you need to use command because service isinsufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of thismessage.192.168.227.28 | FAILED | rc=2 >>[Errno 2] No such file or directory$ ansible web -m command -a "service ntpd status" --limit "192.168.227.28" -u byrd -b[WARNING]: Consider using the service module rather than running 'service'. If you need to use command because service isinsufficient you can add 'warn: false' to this command task or set 'command_warnings=False' in ansible.cfg to get rid of thismessage.192.168.227.28 | CHANGED | rc=0 >>● ntpd.service - Network Time ServiceLoaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)Active: active (running) since Tue 2019-06-18 15:47:21 CST; 5min agoProcess: 16630 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)Main PID: 16631 (ntpd)CGroup: /system.slice/ntpd.service└─16631 /usr/sbin/ntpd -u ntp:ntp -gJun 18 15:47:21 Web1.t4x.org ntpd[16631]: Listen normally on 3 ens33 192.168.227.28 UDP 123Jun 18 15:47:21 Web1.t4x.org ntpd[16631]: Listen normally on 4 lo ::1 UDP 123Jun 18 15:47:21 Web1.t4x.org ntpd[16631]: Listen normally on 5 ens33 fe80::20c:29ff:fe01:1915 UDP 123Jun 18 15:47:21 Web1.t4x.org ntpd[16631]: Listening on routing socket on fd #22 for interface updatesJun 18 15:47:21 Web1.t4x.org ntpd[16631]: 0.0.0.0 c016 06 restartJun 18 15:47:21 Web1.t4x.org ntpd[16631]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPMJun 18 15:47:21 Web1.t4x.org ntpd[16631]: 0.0.0.0 c011 01 freq_not_setJun 18 15:47:28 Web1.t4x.org ntpd[16631]: 0.0.0.0 c61c 0c clock_step -72.966935 sJun 18 15:46:15 Web1.t4x.org ntpd[16631]: 0.0.0.0 c614 04 freq_modeJun 18 15:46:16 Web1.t4x.org ntpd[16631]: 0.0.0.0 c618 08 no_sys_peerRedirecting to /bin/systemctl status ntpd.service
8:新建用户
SourceByrd's Weblog-https://note.t4x.org/basic/ansible-ad-hoc/
0123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 $ ansible web -m group -a "name=http gid=498 state=present system=yes" -u byrd -b192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"gid": 498,"name": "http","state": "present","system": true}$ ansible web -m user -a "name=http uid=498 shell=/sbin/nologin group=http append=yes state=present system=yes" -u byrd -b192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"comment": "","create_home": true,"group": 498,"home": "/home/http","name": "http","shell": "/sbin/nologin","state": "present","system": true,"uid": 498}$ ansible web -m user -a "name=http groups=byrd append=no" -u byrd -b192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"append": false,"changed": true,"comment": "","group": 498,"groups": "byrd","home": "/home/http","move_home": false,"name": "http","shell": "/sbin/nologin","state": "present","uid": 498}$ ansible web -m user -a "name=http groups=http append=no" -u byrd -b192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"append": false,"changed": true,"comment": "","group": 498,"groups": "http","home": "/home/http","move_home": false,"name": "http","shell": "/sbin/nologin","state": "present","uid": 498}$ ansible web -m user -a "name=http state=absent remove=yes" -u byrd -b192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"force": false,"name": "http","remove": true,"state": "absent","stderr": "userdel: http mail spool (/var/spool/mail/http) not found\n","stderr_lines": ["userdel: http mail spool (/var/spool/mail/http) not found"]}$ ansible web -m user -a "name=http uid=498 shell=/sbin/nologin group=http append=yes state=present system=yes " -u byrd -t system=yes expires=1560846258" -u byrd -b192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"changed": true,"comment": "","create_home": true,"group": 498,"home": "/home/http","name": "http","shell": "/sbin/nologin","state": "present","system": true,"uid": 498}$ ansible web -m user -a "name=byrd shell=/bin/bash password=bynwXEWgZfiUg update_password=always" -u byrd -b[WARNING]: The input password appears not to have been hashed. The 'password' argument must be encrypted for this module to workproperly.192.168.227.28 | CHANGED => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"},"append": false,"changed": true,"comment": "","group": 2770,"home": "/home/byrd","move_home": false,"name": "byrd","password": "NOT_LOGGING_PASSWORD","shell": "/bin/bash","state": "present","uid": 2770}$ python3Python 3.6.5 (default, Jun 18 2019, 12:09:59)[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import crypt>>> print(crypt.crypt("123456", "byrd"))bynwXEWgZfiUg
0 1 2 3 4 |
$ yum install python python-devel libevent-devel gcc gcc-c++ libffi-devel openssl-devel $ wget https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz $ tar zxf pycrypto-2.6.1.tar.gz $ cd pycrypto-2.6.1 $ python setup.py install |
0 1 2 3 4 5 6 7 8 9 |
https://pypi.python.org/packages/source/s/setuptools/setuptools-7.0.tar.gz # tar -xvzf setuptools-7.0.tar.gz # cd setuptools-7.0 # python setup.py install # git clone https://github.com/ansible/ansible.git --recursive easy_install pip mkdir /etc/ansible/ # cp examples/ansible.cfg /etc/ansible/ ssh-keygen -t rsa # ssh-copy-id -i /root/.ssh/id_rsa.pub 192.168.190.106 |
0 |
ansible 10.1.21.247 -m setup -i hosts|grep ansible_os_family |
参考:
1:https://pypi.org/search/?q=pycrypto
2:https://releases.ansible.com/ansible/SourceByrd's Weblog-https://note.t4x.org/basic/ansible-ad-hoc/ SourceByrd's Weblog-https://note.t4x.org/basic/ansible-ad-hoc/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!