Ansible automatic operation and maintenance (ii)
(2) Configuring and using Ansible
#复制配置文件
mkdir/etc/ansible/
CP examples/ansible.cfg/etc/ansible/
CP examples/hosts/etc/ansible/
#修改/etc/ansible/hosts, you can use IP or domain name instead
[Hadoop]
Master
Node1
Node2
Node3
[Other]
All
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7E/AC/wKiom1cGd6OjyBpzAAGGn73N3-8667.png "/>
#修改/etc/ansible/ansible.cfg
Private_key_file =/root/.ssh/id_rsa
#启动测试及常用命令
Ansible hadoop-m command-a ' uptime '
Ansible hadoop-m Ping
#
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7E/A8/wKioL1cGeFLTIiYxAAGW3-_6JXw457.png "/>
#常用模块
Ansible hadoop-m Setup
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7E/AC/wKiom1cGd6XjIAqlAAIj7jYD2zU612.png "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/7E/A8/wKioL1cGeFSjJiy0AAITlZJ9Wi8838.png "/>
#file设置文件属性
Ansible hadoop-m file opt
#选项如下 (option description selected from Network)
Force: There are two cases of forcing the creation of a soft link, one where the source file does not exist, but it will be established later, the other is the target soft link already exists, need to first cancel the previous soft chain, and then create a new soft chain, there are two options: Yes|no
Group: Defines the genus of files/directories
Mode: Define permissions for files/directories
Owner: Defines a file/directory owner
Path: Required option, defines the path to the file/directory
Recurse: Recursive settings file properties, only valid for directory
SRC: The path of the source file being linked, only for the case of State=link
Dest: The path to be linked to only the State=link case
State
Directory: Create directories if the directory does not exist
File: Will not be created even if it does not exist
Link: Create a soft link
Hard: Create a rigid link
Touch: If the file does not exist, a new file is created and the last modified time is updated if the file or directory already exists.
Absent: Deleting directories, files, or unlinked files
#创建和删除远程文件符号链接
Ansible hadoop-m file-a "src=/home/all.sh dest=/tmp/all.sh state=link"
Ansible hadoop-m file-a "path=/tmp/all.sh state=absent"
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7E/AC/wKiom1cGd6ei5sUJAAHjihbLOiQ461.png "/>
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/7E/AC/wKiom1cGd6iTiQOwAAIle6EY4JQ562.png "/>
#copy复制文件到远程主机 (option description selected from Network)
Backup: Before overwriting, the source file is backed up, and the backup file contains the time information. There are two options: Yes|no
Content: Used instead of "src", you can set the value of the specified file directly
Dest: Required option. 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 set permissions for the directory, default to system default permissions
Force: If the target host contains the file, but the content is different, if set to Yes, the override is enforced, and if no, the file is copied only if the target location for the destination host does not exist. The default is Yes
Others: All the options in the file module can be used here
SRC: A local file that is copied to the remote host, either an absolute path or a relative path. If the path is a directory, it will be replicated recursively. In this case, if the path ends with "/", only the contents of the directory are copied, and if "/" is not used to end, the entire content, including the directory, is copied, similar to rsync.
Ansible automatic operation and maintenance (ii)