定义变量安装多服务
1 2 3 4 5 6 7 8 9 10 11 12 |
[root@m01 ~]# vim install.yml - hosts: nfs tasks: - name: Install Server yum: name: "{{ package }}" state: present vars: package: - httpd - nfs-utils - mariadb-server |
定义变量启动多服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@m01 ~]# cat install.yml - hosts: nfs vars: package: - httpd - nfs-utils - mariadb-server tasks: - name: Install Server yum: name: "{{ package }}" state: present - name: Start Server systemd: name: "{{ item }}" state: started enabled: yes with_items: - httpd - nfs-utils - mariadb |
字典定义变量
1)创建多个用户组
1 2 3 4 5 6 7 8 |
- name: Create www Group group: name: "{{ item.name }}" gid: "{{ item.gid }}" with_items: - { name: www, gid: 666 } - { name: lhd, gid: 777 } - { name: dsb, gid: 888 } |
2)创建多个用户
1 2 3 4 5 6 7 8 9 10 11 |
- name: Create www User user: name: "{{ item.name }}" uid: "{{ item.uid }}" group: "{{ item.name }}" shell: "{{ item.shell }}" create_home: "{{ item.create_home }}" with_items: - { name: www, uid: 666, shell: "/sbin/nologin", create_home: no } - { name: lhd, uid: 777, shell: "/bin/bash", create_home: no } - { name: dsb, uid: 888, shell: "/bin/bash", create_home: yes } |