In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
According to the official classification of zs, the modules are classified into cloud module, command module, database module, file module, asset module, message module, monitoring module, network module, notification module, package management module, source code control module, system module, unit module, web facilities module, windows module. For more information, please see the official page.
Here, some of the most commonly used modules are selected from the official classification modules for introduction.
1. Ping module
To test whether the host is accessible, the usage is simple and does not involve parameters:
Ansible test-m ping
2. Setup module
Setup module, which is mainly used to obtain host information, is related to a parameter gather_facts that is often used in playbooks. One of the parameters commonly used under the setup module is the filter parameter. Specific examples are as follows:
Ansible 10.212.52.252-m setup-a 'filter=ansible_*_mb' / / View host memory information
Ansible 10.212.52.252-m setup-a 'filter=ansible_eth [0-2]' / / View the Nic information with eth0-2 interface
Ansible all-m setup-- tree / tmp/facts / / enter the information of all hosts into the / tmp/facts directory, and the information of each host into the hostname file (hostname in / etc/ansible/hosts). 3. File module
The file module is mainly used for file manipulation on remote hosts, and the file module contains the following options:
Force: you need to force the creation of a soft link in two cases, one is if the source file does not exist but will be established later, and the other is that the destination soft link already exists and you need to cancel the previous soft link and then create a new one. There are two options: yes | no
Group: define the subordinate group of the file / directory
Mode: define permissions for files / directories
Owner: define the owner of the file / directory
Path: required, define the path to the file / directory
Recurse: recursively sets the properties of the file, valid only for directories
Src: the path of the source file to be linked, only in the case of state=link
Dest: the path to be linked to, only in the case of state=link
State:
Directory: if the directory does not exist, create the directory
File: even if the file does not exist, it will not be created
Link: creating soft links
Hard: creating hard links
Touch: if the file does not exist, a new file is created, and if the file or directory already exists, its last modification time is updated
Absent: delete directories, files, or unlink files
Examples of use:
Ansible test-m file-a "src=/etc/fstab dest=/tmp/fstab state=link"
Ansible test-m file-a "path=/tmp/fstab state=absent"
Ansible test-m file-a "path=/tmp/test state=touch" IV. Copy module
To copy files to a remote host, the copy module contains the following options:
Backup: back up the original file before overwriting. The backup file contains time information. There are two options: yes | no
Content: used instead of "src", you can directly set the value of the specified file
Dest: required. The absolute path of the remote host to which the source file is to be copied, and if the source file is a directory, the path must also be a directory
Directory_mode: recursively sets the permissions of the directory, which defaults to the system default permissions
Force: if the target host contains the file, but the content is different, if it is set to yes, it is forced to be overwritten, and if it is no, it is copied only if the file does not exist at the target host's destination location. Default is yes
Others: the options in all file modules can be used here
Src: the local address of the file to be copied to the remote host, either an absolute path or a relative path. If the path is a directory, it will be copied recursively. In this case, if the path ends with "/", only the contents of the directory are copied, and if it does not end with "/", the entire content, including the directory, is copied, similar to rsync.
Validate: The validation command to run before copying into place. The path to the file to validate is passed in via'% s' which must be present as in the visudo example below.
Examples are as follows:
Ansible test-m copy-a "src=/srv/myfiles/foo.conf dest=/etc/foo.conf owner=foo group=foo mode=0644"
Ansible test-m copy-a "src=/mine/ntp.conf dest=/etc/ntp.conf owner=root group=root mode=644 backup=yes"
Ansible test-m copy-a "src=/mine/sudoers dest=/etc/sudoers validate='visudo-cf% s'" V. Service module
Used to manage servic
The module contains the following options:
Arguments: provide some options for the command line
Enabled: whether to enable yes. | no
Name: required, service name
Pattern: defines a pattern. If there is no response when viewing the status of the service through the status instruction, it will look up the service according to the pattern in the process through the ps directive. If it matches, the service is still running.
Runlevel: run level
Sleep: if restarted is executed, sleep for a few seconds between stop and start
State: perform operations such as start, stop, restart, reload, etc. (started,stopped,restarted,reloaded) on the current service
Examples of use:
Ansible test-m service-a "name=httpd state=started enabled=yes"
Asnible test-m service-a "name=foo pattern=/usr/bin/foo state=started"
Ansible test-m service-a "name=network state=restarted args=eth0" VI. Cron module
The following options are included for managing scheduled tasks:
Backup: make a backup before modifying the original task schedule on the remote host
Cron_file: if specified, this file replaces the task schedule of the user in the cron.d directory on the remote host
Day: day (1-31). )
Hour: hours (0-23). )
Minute: minutes (0-59 minutes). )
Month: month (1-12 months). )
Weekday: Zhou (0-7). )
Job: tasks to be performed, depending on state=present
Name: description of the task
Special_time: specify when to execute. Parameter: reboot,yearly,annually,monthly,weekly,daily,hourly
State: confirm whether the task schedule is created or deleted
User: as which user to execute
Example:
Ansible test-m cron-a 'name= "a job for reboot" special_time=reboot job= "/ some/job.sh"'
Ansible test-m cron-a 'name= "yum autoupdate" weekday= "2" minute=0 hour=12 user= "root
Ansible test-m cron-a 'backup= "True" name= "test" minute= "0" hour= "5" job= "ls-alh > / dev/null"'
Ansilbe test-m cron-a 'cron_file=ansible_yum-autoupdate state=absent' VII, yum module
Use the yum package manager to manage packages with the following options:
Configuration file for config_file:yum
Disable_gpg_check: turn off gpg_check
Disablerepo: do not enable a source
Enablerepo: enable a source
Name: the name of the software package to be operated on, or you can pass a url or the path of a local rpm package
State: status (present,absent,latest)
Examples are as follows:
Ansible test-m yum-a 'name=httpd state=latest'
Ansible test-m yum-a 'name= "@ Development tools" state=present'
Ansible test-m yum-a 'name= http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm state=present' VIII, user module and group module
The user module requests three instructions: useradd, userdel and usermod, while the goup module requests three instructions: groupadd, groupdel and groupmod.
1. User module
Home: specify the user's home directory, which needs to be used with createhome
Groups: specifies the subordinate group of the user
Uid: the uid specified for use
Password: specify the user's password
Name: specify user name
Createhome: whether to create a home directory yes | no
System: whether it is a system user or not
Remove: when state=absent, remove=yes is deleted along with the home directory, which is equivalent to userdel-r
State: create or delete
Shell: specifies the shell environment of the user
Examples of use:
User: name=johnd comment= "John Doe" uid=1040 group=admin
User: name=james shell=/bin/bash groups=admins,developers append=yes user: name=johnd state=absent remove=yes
User: name=james18 shell=/bin/zsh groups=developers expires=1422403387
User: when name=test generate_ssh_key=yes ssh_key_bits=2048 ssh_key_file=.ssh/id_rsa # generates a key, only the public key file and the private key file are generated, which is the same as using the ssh-keygen directive directly, but not the authorized_keys file.
Note: the plaintext password cannot be used when specifying the password parameter, because the latter string of passwords will be transferred directly to the / etc/shadow file of the managed host, so the password string needs to be encrypted first. Then put the resulting string into password.
Echo "123456" | openssl passwd-1-salt $(< / dev/urandom tr-dc'[: alnum:]'| head-c 32)-stdin
$1 $4P4PlFuE$ur9ObJiT5iHNrb9QnjaIB0
# create a user with the password above
Ansible all-m user-a 'name=foo password= "$1 $4P4PlFuE$ur9ObJiT5iHNrb9QnjaIB0"'
The default encryption methods used by different distributions may vary. Check the / etc/login.defs file to confirm that centos version 6.5 uses the SHA512 encryption algorithm.
2. Group example ansible all-m group-a 'name=somegroup state=present'
IX. Synchronize module
Use rsync to synchronize files with the following parameters:
Archive: archiving, which is equivalent to enabling recursive (recursive), links, perms, times, owner, group,-D options are all yes. This is enabled by default.
Checksum: skip detection of sum value and turn it off by default
Compress: whether to enable compression
Copy_links: copy the linked file. The default is no. Note that there is a links parameter after it.
Delete: delete files that do not exist. Default no
Dest: directory path
Dest_port: the port on the default directory host, which defaults to 22, following the ssh protocol
Dirs: the speed directory is not recursive. The default is no, that is, directory recursion.
Rsync_opts:rsync parameter part
Set_remote_user: mainly used in cases where the user defined or used by default in / etc/ansible/hosts is different from the user used by rsync
Mode: push or pull module, if push mode, is generally used to upload files from the local machine to a remote host, and pull mode is used to retrieve files from the remote host.
Examples of use:
Src=some/relative/path dest=/some/absolute/path rsync_path= "sudo rsync"
Src=some/relative/path dest=/some/absolute/path archive=no links=yes
Src=some/relative/path dest=/some/absolute/path checksum=yes times=no
Src=/tmp/helloworld dest=/var/www/helloword rsync_opts=--no-motd,--exclude=.git mode=pull X. filesystem module
Create a file system on a block device
Options:
Dev: target block Devic
Force: force creation on a device that already has a file system
Fstype: type of file system
Opts: options passed to the mkfs command
Example:
Ansible test-m filesystem-a 'fstype=ext2 dev=/dev/sdb1 force=yes'
Ansible test-m filesystem-a 'fstype=ext4 dev=/dev/sdb1 opts= "- cc"'
11. Mount module
Configure mount point
Options:
Dump
Fstype: required, type of mounted file
Name: required, mount point
Opts: parameters passed to the mount command
Src: required, files to be mounted
State: required
Present: only deal with configuration in fstab absent: delete mount point mounted: automatically create mount point and mount umounted: uninstall
Example:
Name=/mnt/dvd src=/dev/sr0 fstype=iso9660 opts=ro state=present
Name=/srv/disk src='LABEL=SOME_LABEL' state=present
Name=/home src='UUID=b3e48f45-f933-4c8e-a700-22a159ec9077' opts=noatime state=present ansible test-a'dd if=/dev/zero of=/disk.img bs=4k count=1024'
Ansible test-a 'losetup / dev/loop0 / disk.img'
Ansible test-m filesystem 'fstype=ext4 force=yes opts=-F dev=/dev/loop0'
Ansible test-m mount 'name=/mnt src=/dev/loop0 fstype=ext4 state=mounted opts=rw' XII, get_url module
This module is mainly used to download files from http, ftp, and https servers (similar to wget), and has the following options:
Sha256sum: sha256 check after downloading
Timeout: download timeout. Default is 10s.
Url: downloaded URL
Url_password, url_username: mainly used in situations where username and password are required for authentication
Use_proxy: it is necessary to use the agent, which needs to be defined in the environment change in advance.
Example:
Get_url: url= http://example.com/path/file.conf dest=/etc/foo.conf mode=0440
Get_url: url= http://example.com/path/file.conf dest=/etc/foo.conf sha256sum=b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c
XIII. Unarchive module
Used to extract files, the module contains the following options:
Copy: whether to copy the file to the remote host before unzipping the file. Default is yes. If no, the compressed package must exist on the target host.
Creates: specify a file name that will not be executed when the file exists
Dest: a path on the remote host, that is, the path to decompress the file
Grop: the group of unzipped directories or files
List_files: if yes, the files in the package will be listed. The default is the option added in no,2.0 version.
Mode: permissions of files after resolution
Src: if copy is yes, you need to specify the source path of the compressed file
Owner: the owner of the decompressed file or directory
Examples are as follows:
-unarchive: src=foo.tgz dest=/var/lib/foo
-unarchive: src=/tmp/foo.zip dest=/usr/local/bin copy=no
-unarchive: src= https://example.com/example.zip dest=/usr/local/bin copy=no
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.