Centralized management platform ansible (1)

Source: Internet
Author: User
Tags cloud computing platforms ansible modules
What is ansible?

Ansible is an open-source platform that integrates IT system configuration management, application deployment, and execution of specific tasks. It is based on the Python language and is built by paramiko and pyyaml. It integrates the advantages of many O & M tools (puppet, cfengine, Chef, func, fabric), and implements features such as batch system configuration, batch program deployment, and batch run commands. Ansible works based on modules and does not support batch deployment. The modules run by ansible are actually deployed in batches. ansible only provides a framework.

Ansible advantages
  • The deployment is simple. You only need to deploy the ansible environment on the master, and the control end does not need to perform any operations;
  • By default, the SSH (Secure Shell) protocol is used to manage devices;
  • Centralized master-slave management;
  • Simple configuration, powerful functions, and strong scalability;
  • Supports APIs and custom modules and can be easily expanded using python;
  • Use playbooks to customize powerful configuration and status management;
  • Good support for cloud computing platforms and big data;
  • Provides a powerful and operable web management interface and rest API interface-awx platform;
  • Idempotence: An operation repeats multiple times and returns the same result.
Ansible installation and testing
  1. Epel source configuration
    [Epel] # configure Tsinghua epelname = fedora epelbaseurl = https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64/gpgcheck=0
  2. Install yum
    yum install ansible -y -q
  3. Ansible Configuration
    # Add host information to the ansible configuration file to communicate with the target host. The configuration file location is/etc/ansible/hosts, where [web] [test] is the master unit, you can batch control all hosts in a host group. A host can be added to multiple groups. [[Email protected] ~] #/Etc/ansible/ingress [web] 172.18.153.101172.18.153.103 [dB] 172.18.153.102172.18.153.103 "/etc/ansible/hosts" 49l, 1092c
  4. Test
    [[Email protected] ~] # Ansible test -- list # view User Group member hosts (2): 172.18.153.27172.18.153.37 # configure SSH equivalence [email protected] ~] # Ssh-keygen [[email protected] ~] # Ssh-copy-ID [email protected] [[email protected] ~] # Ssh-copy-ID [email protected] [[email protected] ~] # Ssh-copy-ID [email protected] [[email protected] ~] # Ansible all-M Ping # test connectivity. If Pong is displayed, 172.18.153.103 is successfully managed. | Success => {"changed": false, "ping ": "PONG"} 172.18.153.102 | Success => {"changed": false, "ping": "PONG"} 172.18.153.101 | Success => {"changed": false, "ping ": "PONG"} [[email protected] ~] # Ansible all-M command-A 'useradd zhangfei' # therefore, the host creation user-M Comand uses the command module-a to add the parameter 172.18.153.103 | changed | rc = 0> 172.18.153.101 | changed | rc = 0> 172.18.153.102 | changed | rc = 0> [email protected] ~] # Ansible all-M command-a 'id zhangfei' # Success 172.18.153.101 | changed | rc = 0> uid = 1001 (Zhangfei) gid = 1001 (Zhangfei) group = 1001 (Zhangfei) 172.18.153.103 | changed | rc = 0> uid = 1002 (Zhangfei) gid = 1002 (Zhangfei) group = 1002 (Zhangfei) 172.18.153.102 | changed | rc = 0> uid = 1001 (Zhangfei) gid = 1001 (Zhangfei) group = 1001 (Zhangfei)
Use of ansible modules

1. Remote Command Module

  • Command: the default module that can run all shell commands in the remote permission range.
  • Script: Execute the shell script file stored on the master control end on the remote host, which is equivalent to the SCP + shell combination.
  • Shell: Execute the shell script of the remote host to ask the file
[[email protected] ~]# ansible web -m command -a "free -m"[[email protected] ~]# ansible web -m script -a "/root/hello.sh 12 34"[[email protected] ~]# ansible web -m shell -a "/root/hello.sh"

2. Copy Module
Achieve the master control end to copy objects. Similar to SCP

# Copy/etc/fstab to the target host/tmp/of the web group, and update the file owner and permissions. [[email protected] ~] # Ansible web-M copy-a "src =/etc/fstab DEST =/tmp/owner = root group = root mode = 0744"

3. Stat Module
Obtain the status information of remote files, such as atime, MD5, and uid.

[[email protected] ~]# ansible web -m stat -a "path=/etc/fstab"

4. get_url Module
Allows the remote host to download the specified URL to the local device. The sha256sum checksum is supported.

[[email protected] ~]# ansible web -m get_url -a "url=http://www.baidu.com dest=/tmp/index.html mode=0440 force=yes"

5. Yum Module
Linux software package management module

[[email protected] ~]# ansible web -m yum -a "name=curl state=latest"

6. cron Module
Scheduled task configuration of the remote host

[[Email protected] ~] # Ansible web-M Cron-a 'minute = * weekday = 2, 4, 6 Job = "/usr/bin/wall FBI warning" name = warningcron' [[email protected] ~] # Crontab-L # Check the effect on the node # ansible: warningcron ***** 2, 4, 6/usr/bin/wall FBI warning [email protected] ~] # Ansible all-M Cron-a 'name = warningcron state = absent '# cancel [email protected] ~] # Ansible all-M Cron-A 'Disabled = true job = "/usr/bin/wall FBI warning" name = warningcron' # disable [email protected] ~] # Ansible all-M Cron-A 'Disabled = false job = "/usr/bin/wall FBI warning" name = warningcron' # enable

7. Mount Module
Remote Host mounting

[[email protected] ~]# ansible web -m mount -a "name=/mnt/data dest=/dev/sd0 fstype=ext3 opts=ro state=present"

8. Fetch Module
Pull files from managed hosts

[Email protected] ~] # Ansible all-M fetch-A 'src =/var/log/messages DEST =/root/ansible '# If You Want To transmit multiple files using fetch or copy, you can only package [email protected] ~] # Ansible all-M shell-A 'tar JCF/root/log.tar. xz/var/log/*. log' [email protected] ~] # Ansible all-M fetch-A 'src =/root/log.tar. xz DEST =/root/ansible'

9. Service Module
Remote Host System Service Management

[[email protected] ~]# ansible web -m mount -a "name=httpd state=restart"

Ansible has a total of 2080 modules so far, and you need to explore them slowly. I will list more modules here.

[[Email protected] ~] # Ansible-doc-S-L # list all modules [[email protected] ~] # Ansible-Doc fetch # view the detailed module help document [[email protected] ~] # Ansible-doc-s fetch # view the help document of the module

Centralized management platform ansible (1)

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.