有关template参数
{% for i in li %}
hello {{ i }}
{% endfor %}
{% if name == "shark" %}
...
{% endif %}
![template.png](https://upload-images.jianshu.io/upload_images/18339928-67d8fcc8891df07c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
class:
- name: stu1
num: 001
- name: stu2
num: 002
- name: stu3
num: 003
python -c 'import yaml,sys,pprint; pprint.pprint(yaml.load(sys.stdin))' < test.ym
读出内容
{'class': [{'name': 'stu1', 'num': 1},
{'name': 'stu2', 'num': 2},
{'name': 'stu3', 'num': 3}]}
---
- name: one nginx yaml
hosts: host1
remote_user: root
tasks:
- name: install epel
yum: name=epel-release state=present
- name: install nginx
yum: name=nginx state=present
- name: start nginx server
systemd:
name: nginx
enabled: true
state: started
...
ansible-playbook nginx.yml --step
# 就会启动
---
- name: add a user
hosts: host1
vars:
user_name: liangzai
home_dir: /home/liangzai
tasks:
- name: add a user and space them home work
user:
name: "{{ user_name }}"
home: "{{ home_dir }}"
...
创建一个用户还有家目录
ansible-playbook add.yml