In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
1. Ansible Management Task Plan
# ansible testhost-m cron-a "name='test cron' job='/bin/touch / tmp/1212.txt' weekday=6"
Name specifies the name of the task plan, job specifies what its command is, and then specifies its time-sharing, day, month and week, which is * without definition.
[root@yw02] # crontab-l#Ansible: test cron* 6 / bin/touch / tmp/1212.txt
The first line must not be changed, and once changed, you cannot use this tool to manipulate it.
To delete the cron, just add a field state=absent
# ansible testhost-m cron-a "name='test cron' state=absent"
Other times are: minute minute, hour hour, date day, month month.
II. Ansible installs RPM packages and management services
# ansible testhost-m yum-a "name=httpd"
You can add state=installed/removed installation / uninstall after name
Start the httpd service and use the module to teach service:
# ansible testhost-m service-a "name=httpd state=started enabled=yes"
After starting the service, you can see it on the ps aux on the machine.
The name here is the name of the service in the centos system, which can be found through chkconfig-list.
The use of Ansible documents
Ansible-doc-l lists all modules
Ansible-doc cron looks at the documentation for the specified module, which is equivalent to the man configuration in the system.
3. Playbook using ansible
To put it bluntly, playbook just put all the configurations into one configuration file, and then execute the configuration file.
It is equivalent to writing the module to the configuration file, for example:
# vi / etc/ansible/test.yml / / add the following-hosts: yw02 remote_user: root tasks:-name: test_playbook shell: touch / tmp/lishiming.txt
Description: file format, suffix is yml; the first line needs to have three bars, is a fixed format; hosts parameter specifies which hosts to operate on, if multiple machines can be separated by commas, you can also use host groups, defined in / etc/ansible/hosts
The user parameter specifies which user to use to log in to the remote host operation
Tasks specifies a task, and the following name parameter is also a description of the task, which will be printed during execution. Shell is the name of the ansible module.
Execute: ansible-playbook test.yml
PLAY [yw02] * * TASK [Gathering Facts] * * ok: [yw02] TASK [test_playbook] * * [WARNING]: Consider using the file module with state=touch rather than running 'touch'. If you need to use command because file isinsufficient you can add 'warn: false' to this command task or set' command_warnings=False' in ansible.cfg to get rid of thismessage.changed: [yw02] PLAY RECAP * * yw02: ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
4. Variables in playbook
Let's take another example of creating a user:
# vi / etc/ansible/create_user.yml / / add the following-name: create_user hosts: yw02 user: root gather_facts: false vars:-user: "test" tasks:-name: create user user: name= "{user}}"
Description:
The name parameter gives an overview of the functions implemented by the playbook. During later execution, the value of the name variable is printed, which can be omitted.
The gather_facts parameter specifies whether to execute the setup module to obtain information about the host before the following tasks are executed, which is used when the later task uses the information obtained by setup. If you do not write this line, the facts will be collected by default. If there are too many machines, the recommendation will not be collected, which will affect the execution efficiency and put pressure on the ansible.
Parameter vars, which specifies the variable. Here, specify a user variable whose value is test. It should be noted that the value of the variable must be enclosed in quotation marks.
The user under tasks specifies to call the user module, name is a parameter in the user module, and the added user name calls the value of the above user variable, {{user}} = test.
[root@fuxi01 ansible] # ansible-playbook create_user.yml PLAY [create_user] * * TASK [create user] * * changed: [yw03] PLAY RECAP * * * yw03: ok=1 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
If the test user already exists, it will not be created, changed=0.
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.