#cat create_user.yaml
---
- name: create user for machine
hosts: devops
tasks:
- name: create user for machine
user:
name: natasha
comment: system-user
uid: 1040
group: daemon
password: "{{'1' | password_hash('sha512')}}"
#cat create_james.yaml
---
- name: create james for mysql
hosts: all
tasks:
- name: create user james for mysql,with shell /bin/bash and groups is adm,daemon
user:
name: james
#shell: /bin/bash#groups: adm,daemon
password: "{{'12' | password_hash('sha512')}}"
#删除james用户#cat delete_james.yaml
---
- name: delete user for james
hosts: all
tasks:
- name: delete user foe james
user:
name: james
state: absent
2.yum/service安装软件包
#cat install_pkgs.yaml
---
- hosts: dbservers
tasks:
- name: install a list of software
yum:
name:
- httpd
- mariadb
- mariadb-server
- name: install a group software
yum:
#@表示安装组包
name: "@Development tools"
- name: update software
yum:
#*表示匹配所有
name: "*"#更新到最新版本
state: latest
#cat register.yaml
---
- hosts: devops
tasks:
- name: save shell result to a variable
shell: hostname
register: myvar
- name: print the variable's vlaue through debug
debug:
msg: "{{myvar}}"
#cat register_1.yaml
---
- hosts: devops
tasks:
- name: save shell result to a variable
shell: hostname
register: myvar
- name: print the variable's vlaue through debug
debug:
#此处注意层级关系
msg: "{{myvar.stdout}}"