After installing ansible, we can use it through seven main instructions, which are: ansible, ansible-doc, ansible-galaxy, ansible-lint, ansible-playbook, ansible-pull, ansible-vault. We can learn how to use them by looking at the usage section of the command, and detailed information can be obtained by running "command -h".
Ansible common commands
The core part of Ansible is used to execute ad-hoc commands, that is, a single command. By default, the command needs to specify the host and option parts. If no module is specified, the command module is used by default. However, the module used by default can be modified in /etc/ansible/ansible.cfg, for example #module_name = command.
ansible 192.168.182.130 -a 'date'
This command is used to view module information. Commonly used parameters include -l and -s
#列出所有已安装的模块ansible-doc-l ansible-doc-l #查看具体某模块的用法,这里如查看command模块 ansible-doc-s command
ansible-playbook command is the most commonly used command. It reads the playbook file and then performs corresponding actions. This will be discussed later.
The ansible-galaxy command can easily download third-party extension modules from https://galaxy.ansible.com/, similar to centos' yum, python's pip or easy_install.
ansible-galaxy install aeriscloud.docker
ansible-lint is a tool for checking the syntax of playbook. Usage is as follows:
ansible-lint playbook.yml
The use of this instruction requires talking about another mode of ansible, pull mode, which is exactly the opposite of the push mode we usually use. It is suitable for the following scenarios: you have a huge number of machines that need to be configured, even if the usage is very high The threads still take a lot of time; you'll want to run Anisble on a machine without network connectivity, such as after installing it on boot.
The above is the detailed content of Seven commonly used commands for Ansible automated operation and maintenance. For more information, please follow other related articles on the PHP Chinese website!