详解ansible批量管理服务(9)
第二个历程: 编写文件信息 tasks: 任务信息编写方式一: nfs服务编写
vim main.yaml - name: 01:install nfs rpcbind yum: name: ['nfs-utils', 'rpcbind'] state: installed - name: 02:copy conf file copy: src=/etc/ansible/ansible_playbook/nfs.conf dest=/etc/{{ conf_file }} notify: - nfs_restart - name: 03:create data dir file: path={{ data_dir }} state=directory owner=nfsnobody group=nfsnobody - name: 04:boot server rpcbind service: name={{ item.name }} state={{ item.state }} enabled={{ item.enabled }} with_items: - {name: "rpcbind", state: "started", enabled: "yes"} - {name: "nfs", state: "started", enabled: "yes"} - name: 01:install nfs yum: name=nfs-utils state=installed - name: 02:mount data dir mount: src=172.16.1.31:{{ data_dir }} path=/mnt fstype=nfs state=mounted - name: 03:check mount info shell: df -h|grep mnt register: mount_info - debug: msg={{ mount_info.stdout_lines }}
tasks: 任务信息编写方式二: tasks:定义任务信息
cd tasks vim main.yaml vim nfs_boot.yaml vim nfs_conf.yaml vim nfs_datadir.yaml vim nfs_install.yaml vim nfs_mount.yaml ######################### vim main.yaml - include_tasks: nfs_install.yaml - include_tasks: nfs_conf.yaml - include_tasks: nfs_datadir.yaml - include_tasks: nfs_boot.yaml - include_tasks: nfs_mount.yaml
vars:定义变量信息
vim main.yaml conf_file: exports data_dir: /data
files:定义需要分发的文件
[root@m01 files]# ll total 4 -rw-r--r-- 1 root root 42 Jul 29 10:34 nfs.conf
handlers:定义触发器信息
vim main.yaml - name: nfs_restart service: name=nfs state=reloaded
总结
以上所述是小编给大家介绍的ansible批量管理服务 ,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对黑区网络网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!