Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Ansible Automated Operation and maintenance (2)

Shulou Source: shulou.com Published: 2022-06-03 07:15:54 11月23日 Update

Ansible Automated Operation and maintenance (2)

(2) configure and use ansible

# copy configuration file

Mkdir / etc/ansible/

Cp examples/ansible.cfg / etc/ansible/

Cp examples/hosts / etc/ansible/

# modify / etc/ansible/hosts, you can use IP or domain name instead

[hadoop]

Master

Node1

Node2

Node3

[other]

All

# modify / etc/ansible/ansible.cfg

Private_key_file = / root/.ssh/id_rsa

# start testing and common commands

Ansible hadoop-m command-a 'uptime'

Ansible hadoop-m ping

# as shown

# Common modules

Ansible hadoop-m setup

# file sets file properties

Ansible hadoop-m file opt

# options are as follows (option description is selected from the network)

Force: you need to force the creation of a soft link in two cases, one is that the source file does not exist but will be established later; 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 a file, valid only for directories

Src: the path to the linked source file, applicable 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

# create and delete symbolic links to remote 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"

# copy copies files to a remote host (option description is selected from the network)

Backup: before overwriting, back up the source file, which 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, it is forced to be overwritten if it is set to yes, and if it is no, it is replicated 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: a local file copied to a remote host, either absolute or relative. 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.

Tags: File directory path link host situation source file destination content permissions recursion two backup attributes common time module network application enforcement Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology macOS MySQL Microsoft