Ansible Simple Application

Source: Internet
Author: User

ansiblebased onPythonDevelopment, the collection of many operations and maintenance toolsthe advantages of the implementation of batch system configuration, batch program deployment, batch Run command and other functions, it realizes configuration management, application deployment, task execution and other functions through SSH, so it is necessary to configure the Ansible side to contact each managed node based on key authentication in advance.

Command format: Ansible

Host-pattern # The address of the destination host, typically the group name in the configuration file

-M module # specifying the application's modules

-a args # Specify parameters for the module

-F #一批并行发出多少请求




Installation:

[email protected] ~]# Yum install ansible

Configuration file:

[Email protected] ansible]# vim/etc/ansible/hosts [frontend][email protected] ansible_ssh_host=marvin.com Ansible_ Ssh_port=6789[email protected] ansible_ssh_host=sherry.com ansible_ssh_port=6789

Test Ping:

[Email protected] ansible]# ansible frontend-m ping[email protected] | SUCCESS = {"Changed": false, "ping": "Pong"}[email protected] | SUCCESS = {"Changed": false, "ping": "Pong"}

Note:The SSH-based authentication mode Ansible only recognizes the public key authorized_keys hereso if you want to operate on this machineWrite your own public key toAuthorized_keysin


List modules:ansible-doc-l

View module: Ansible-doc-s moudle


Here are a few simple command implementations:

Copy: If the directory must have an absolute path, it can be replicated recursively

[[email protected] ansible]# ansible frontend -m copy -a  ' src=/etc/ Hosts dest=/etc/hosts ' [[email protected] ansible]# ansible frontend -m  command -a  ' cat /etc/hosts ' [email protected] | success | rc=0  >>127.0.0.1   localhost localhost.localdomain localhost4  localhost4.localdomain4::1         localhost  localhost.localdomain localhost6 localhost6.localdomain6192.168.1.220 marvin  marvin.com192.168.1.221 sherry sherry.comroot[email protected] | success |  rc=0 >>127.0.0.1   localhost localhost.localdomain localhost4  localhost4.localdomain4::1         localhost  Localhost.localdomain localhost6 localhost6.localdomain6192.168.1.220 maRvin marvin.com192.168.1.221 sherry sherry.com 

crontab Edit Update Time:

[[email protected] ansible]# ansible others -m cron -a  ' name= ' update  time " minute=*/3 hour=* month=* weekday=* job="/usr/sbin/ntpdate marvin  &> /dev/null "' [[email protected] ansible]# ansible others -m  command -a  ' Crontab -l ' [email protected] | success | rc=0 > > #Ansible: update time*/3 * * * * /usr/sbin/ntpdate marvin  &> /dev/null[email protected] | SUCCESS | rc=0 >> #Ansible:  update time*/3 * * * * /usr/sbin/ntpdate marvin &> / Dev/null[email protected] | success | rc=0 >> #Ansible: update  Time*/3 * * * * /usr/sbin/ntpdate marvin &> /dev/null[[email  protected] ansible]# ansible servers -m command -a  ' Date ' [email protected] | success  | rc=0 >>thu may 19 20:19:36 cst 2016[email protected]  | success | rc=0 >>thu may 19 20:19:36 cst 2016[email  protected] | success | rc=0 >>thu may 19 20:19:36 cst  2016[email protected] | SUCCESS | rc=0 >>Thu May 19  20:19:36 cst 2016


group add:

[[email protected] nginx-1.6.3]# ansible frontend  -m group -a  ' Gid=304 system=yes name=nginx ' [email protected] |  success => {     "changed": true,      "GID":  304,      "name":  "Nginx",      "state":  " Present ",     " system ":  true}[email protected] | success = > {     "changed": true,      "GID": 304,       "name":  "Nginx",      "state":  "Present",       "System":  true}[[email protected] nginx-1.6.3]# tail /etc/ groupnginx:x:304: 

Add Users:

[Email protected] home]# ansible frontend-m user-a ' uid=304 system=yes group=nginx createhome=no shell=/sbin/nologin N Ame=nginx '

To delete a user:

[Email protected] home]# ansible frontend-m user-a ' uid=304 state=absent name=nginx remove=yes '

Yum

[Email protected] nginx-1.6.3]# ansible frontend-m yum-a ' Name=openssl-devel state=present '


Ansible Simple Application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.