Learning Ansible playbook using Vagrant

  1. install virtualbox
  2. install Vagrant
  3. mkdir ansible-book && cd ansible-book
  4. vagrant init ubuntu/trusty64
  5. vagrant up
  6. vagrant ssh
  7. vagrant provision

Vagrantfile

Vagrant.configure(2) do |config|
    config.vm.box = "ubuntu/trusty64"
    config.vm.provider "virtualbox" do |vb|
      vb.memory = "1024"
    end
    config.vm.provision "ansible" do |ansible|
      ansible.playbook = "provisioning/playbook.yml"
    end
    config.vm.provision "ansible_local" do |ansible|
      ansible.playbook = "provisioning/playbook.yml"
    end
end

mkdir provisioning under ansible-book

nano playbook.yml

---
- hosts: all
  become: true
  tasks:
    - name: Make sure that we can connect to the machine
  ping:
    - name: Install PHP
      apt: name=php5-cli state=present update_cache=yes
    - name: Install nginx
      apt: name=nginx state=present
    - name: Install mySQL
      apt: name=mysql-server-5.6 state=present

With item way

---
- hosts: all
  become: true
  tasks:
    - name: Make sure that we can connect to the machine
  ping:
    - name: Install required packages
      apt: name={{item}} state=present update_cache=yes
      with_items:
        - php5-cli
        - nginx
        - mysql-server-5.6
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章