ansible安装测试

apt-get install ansible
/etc/ansible/hosts增加

[nginx]
192.168.1.106

/etc/ansible/playbook/
roles site.yaml
site.yaml

- hosts: nginx
  remote_user: root

  roles:

roles/
bash nginx
playbook/roles/bash/tasks/main.yal

- name: 创建用户
  user: name=toy state=present

ls playbook/roles/nginx/

drwxr-xr-x 9 root root 4096 Jul 31 09:54 .
drwxr-xr-x 4 root root 4096 Jul 31 11:15 ..
drwxr-xr-x 2 root root 4096 Jul 31 09:54 default
drwxr-xr-x 2 root root 4096 Aug  1 10:16 files
drwxr-xr-x 2 root root 4096 Jul 31 11:14 handlers
drwxr-xr-x 2 root root 4096 Jul 31 09:54 meta
drwxr-xr-x 2 root root 4096 Aug 29 09:31 tasks
drwxr-xr-x 2 root root 4096 Jul 31 11:14 templates
drwxr-xr-x 2 root root 4096 Jul 31 09:54 vars

cat playbook/roles/nginx/handlers/main.yml

- name: server restart
  service: name=nginx state=restarted

cat playbook/roles/nginx/tasks/main.yml

- include: user.yml
#- name: delsteamshell
#  copy: src=delsteam.sh dest=/tmp/delsteam.sh
#- name: run delsteamshell 
#  shell: /tmp/delsteam.sh

cat playbook/roles/nginx/tasks/main.yml.bak

#- include: user.yml
- name: install nginx
  shell: apt-get install -y nginx-full
- name: provides default.conf
  copy: src=default.conf dest=/etc/nginx/nginx.conf
  tags: nginxconf
  notify:
   - server restart
- name: server start
  service: name=nginx enabled=true state=started

cat playbook/roles/nginx/tasks/user.yml

- name: 创建用户
  user: name=toy state=present

原文出处:iblows -> https://www.iblows.com/index.php/archives/48.html

打赏

如果此文对你有所帮助,请随意打赏鼓励作者^_^