Ansible-playbook Basic Use (iii)

Source: Internet
Author: User

Example:

1, Ping module all CCE Group host survival rate

[[email protected] ~]# ansible cce-m Ping

2. Execute commands with command

[Email protected] ~]# ansible cce-m command-a ' cat/etc/redhat-release '

3. Execute commands using shell module

[Email protected] ~]# ansible cce-m shell-a ' cat/etc/redhat-release '

4. copy files using copy module

[Email protected] ~]# ansible cce-m copy-a "Src=/etc/hosts dest=/root/cce"

[Email protected] ~]# ansible cce-m copy-a "src=/etc/hosts dest=/root/cce owner=nobody"

[Email protected] ~]# ansible cce-m copy-a "src=/etc/hosts dest=/root/cce owner=nobody mode=755"

Make a backup before changing

[Email protected] ~]# ansible cce-m copy-a "src=/etc/hosts dest=/root/cce owner=nobody mode=755 backup=yes"

5. Cron Module Task plan

[Email protected] ~]# ansible cce-m cron-a ' month= "*/5" job= "/usr/sbin/ntpdate 172.16.0.1 &>/dev/null" Name= "Tim Esync "'

View

[Email protected] ~]# ansible cce-m shell-a ' crontab-l '

172.16.253.131 | Success | Rc=0 >>

#Ansible: TimeSync

* * * * */5 */usr/sbin/ntpdate 172.16.0.1 &>/dev/null

172.16.252.193 | Success | Rc=0 >>

#Ansible: TimeSync

* * * * */5 */usr/sbin/ntpdate 172.16.0.1 &>/dev/null

Delete Crontab

[Email protected] ~]# ansible cce-m cron-a ' name= "TimeSync" state= "absent" '

6. Use the Fetch module to pull the directory on the remote host to the local

[Email protected] ~]# ansible cce-m fetch-a ' Src=/root/cce dest=/root/cce '

7. Use the file module to manage files on the remote host

[Email protected] ~]# ansible cce-m file-a ' Path=/root/cce mode=777 '

[Email protected] ~]# ansible test-m file-a ' src=/etc/fstab dest=/root/fstablink state=link '

8. Yum Module installation Apache

[Email protected] ~]# ansible cce-m yum-a ' name=httpd state=present '

9. Use service module to start services

[Email protected] ~]# ansible cce-m service-a ' name=httpd state=restarted '

10. Add Users using Ansible

[Email protected] ~]# ansible cce-m user-a ' name=cce home=/tmp/cce shell=/bin/bash uid=2000 comment= "test User"

Ansible-playbook: script Basic use

Hosts : Hosts executed

Remote_user: A user who executes a script remotely

tasks: Task


1. Use the script one-click Deployment httpd

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/8C/2C/wKioL1hkoUrB17AiAAAp9eWY1K8761.png-wh_500x0-wm_3 -wmp_4-s_2731401758.png "title=" 12.png "alt=" Wkiol1hkourb17aiaaap9ewy1k8761.png-wh_50 "/>

Perform

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M00/8C/2C/wKioL1hkoWzxAEtQAABagvXyWXU174.png-wh_500x0-wm_3 -wmp_4-s_47665331.png "title=" 123.png "alt=" Wkiol1hkowzxaetqaabagvxywxu174.png-wh_50 "/>

2, the use of notify, handlers to control (Note: This can only be used at the end of the script, otherwise it will not be executed)

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/8C/2C/wKioL1hkoY6w6BZeAAAtREi9NuU510.png-wh_500x0-wm_3 -wmp_4-s_4152052912.png "title=" 1234.png "alt=" Wkiol1hkoy6w6bzeaaatrei9nuu510.png-wh_50 "/>

Execution results

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M00/8C/2C/wKioL1hkoauw62G7AABFTBdKbAU245.png-wh_500x0-wm_3 -wmp_4-s_3109313747.png "title=" 213.png "alt=" Wkiol1hkoauw62g7aabftbdkbau245.png-wh_50 "/>

3, the use of tags to carry out special tasks

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8C/30/wKiom1hkoc7gBZ6QAAAkZxGx-Xc501.png-wh_500x0-wm_3 -wmp_4-s_1986173008.png "style=" Float:none; "title=" 22.png "alt=" Wkiom1hkoc7gbz6qaaakzxgx-xc501.png-wh_50 "/>

Perform

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/8C/2C/wKioL1hkoc6zf1g5AABcCyvONyg628.png-wh_500x0-wm_3 -wmp_4-s_889191696.png "style=" Float:none; "title=" 33.png "alt=" Wkiol1hkoc6zf1g5aabccyvonyg628.png-wh_50 "/>


This article from "Char" blog, declined reprint!

Ansible-playbook Basic Use (iii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.