需求,有的主机 需要安装服务并且启动服务,有的主机仅需要安装客户端 不启动服务 :
- name: Install NFS server
yum:
name: nfs-utils
state: present
- name: Configure nfs server
template:
src: exports
dest: /etc/exports
when: ansible_hostname is match "nfs"
- name: Create directory "{{ nfs_dir }}"
file:
path: "{{ nfs_dir }}"
state: directory
owner: www
group: www
when: ansible_hostname is match "nfs"
- name: start Nfs systemd
systemd:
name: nfs
state: started
enabled: yes
when: ansible_hostname is match "nfs"
ansible playbook 原始 nfs.yml 文件
[root@m01 ~/ansible]#cat nfs.yml
- hosts: nfs
tasks:
- name: Install Nfs Server
yum:
name: nfs-utils
state: present
- name: Configure Nfs Server
copy:
src: exports
dest: /etc/
- name: Create Group www
group:
name: www
gid: 666
- name: Create User www
user:
name: www
uid: 666
group: www
shell: /sbin/nologin
create_home: false
- name: Create /code/blog dir
file:
path: /code/blog
state: directory
owner: www
group: www
- name: Start NFS Server
systemd:
name: nfs
state: started
enabled: yes
欢迎来撩 : 汇总all