linghaiyan 发表于 2018-7-30 12:47:27

Ansible 学习笔记

  http://lixcto.blog.51cto.com/4834175/1431247
  http://lixcto.blog.51cto.com/4834175/1431659
  http://rfyiamcool.blog.51cto.com/1030776/1413031
  http://rfyiamcool.blog.51cto.com/1030776/1413387
  http://guoting.blog.51cto.com/8886857/1553451
  http://edu.51cto.com/course/course_id-2032.html
  这里有灿哥的视频。
  磊哥写的有些复杂,还没看懂,
  # cat /etc/ansible/hosts
  
  centos5 ansible_ssh_host=192.168.1.215 ansible_ssh_user=root
  # hosts文件这里没有设置密码,所以运行的时候带了 -k 参数 输入密码,可以设置密码,还可以使用ssh无密码登陆方式。
  # ansible centos5 -m ping -k
  SSH password:
  centos5 | success >> {
  "changed": false,
  "ping": "pong"
  }
  # cat testuser.yaml
  - name: create user
  hosts: centos5
  remote_user: root
  gather_facts: false
  vars:
  - user: "billy"
  tasks:
  - name: create ` user `
  user: name=` user `
  #新建一个用户billy
   # ansible-playbook testuser.yaml -k
  SSH password:
  PLAY ************************************************************
  TASK: **********************************************************
  changed:
  PLAY RECAP ********************************************************************
  centos5                  : ok=1    changed=1    unreachable=0    failed=0

  #>  uid=502(billy) gid=502(billy) groups=502(billy)
  # 安装nginx并开启服务
  # cat nginx.yaml
  - name: install and start nginx
  hosts: centos5
  user: root
  tasks:
  - name: install nginx
  action: yum name=nginx state=latest
  - name: start nginx
  service: name=nginx state=running
  # ansible-playbook nginx.yaml -k
  SSH password:
  PLAY ************************************************
  GATHERING FACTS ***************************************************************
  ok:
  TASK: *********************************************************
  ok:
  TASK: ***********************************************************
  changed:
  PLAY RECAP ********************************************************************
  centos5                  : ok=3    changed=1    unreachable=0    failed=0
页: [1]
查看完整版本: Ansible 学习笔记