root@test:~# cat RestartPHPProcess.yml
---
- name: RestartPHPProcess # 该Task名为RestartPHPProcess
service: name=ssh state=restarted # 调用service模块,重启名为php-# fpm的服务
root@test:~# cat test.yml
---
- hosts: localhost
remote_user: root
tasks:
- name: A Project command
command: ls
- name: RestartPHPProcess
include_tasks: RestartPHPProcess.yml # 引用RestartPHPProcess.yml文件 # 调用该文件中定义的功能集
ansible-playbook test.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [localhost] **********************************************************************************************************************************************************************************************************************************************************
TASK [Gathering Facts] ****************************************************************************************************************************************************************************************************************************************************
ok: [localhost]
TASK [A Project command] **************************************************************************************************************************************************************************************************************************************************
changed: [localhost]
TASK [RestartPHPProcess] **************************************************************************************************************************************************************************************************************************************************
included: /root/RestartPHPProcess.yml for localhost
TASK [RestartPHPProcess] **************************************************************************************************************************************************************************************************************************************************
changed: [localhost]
PLAY RECAP ****************************************************************************************************************************************************************************************************************************************************************
localhost : ok=4 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
标签:include,name,TASK,ansible,test,RestartPHPProcess,方法,yml,localhost
From: https://www.cnblogs.com/anyux/p/18355906