Hi, 
I am using vagrant to create 5 servers and using ansible to configure each 
of them to install Nginx and add the the sentence "hello from web 
server{server number}.
I am trying to understand what is best way to configure the playbook to 
configure the servers in one block. Now I use 5 blocks that have the same 
code only the server number is changed(web1, web2,web3, etc) and the number 
I write to the index file.I am using ansible_local. 
  

vagrantfile


    Vagrant.configure("2") do |config|
    
    
        N = 5
        (1..N).each do |machine_id|
            config.vm.define "web#{machine_id}" do |machine|
            machine.vm.box = "ubuntu/trusty64" 
            machine.vm.hostname = "web"
            machine.vm.network "private_network", ip: 
"10.0.0.#{10+machine_id}"
         end
            
        config.vm.provision "ansible_local" do |ansible|
        ansible.playbook = "playbook.yml"
        ansible.become = true
        ansible.extra_vars = { machine: "web#{machine_id}" }
        ansible.groups = {
              "group1" => ["web"],
        }
         end
        end
        



playbook code





    - hosts: web1
      become: true 
      tasks:
        - name: ensure nginx is at the latest version
          apt: name=nginx state=latest
        - name: start nginx
          service:
              name: nginx
              state: started
        - name: add server name to nginx html
          lineinfile:
           dest: /usr/share/nginx/html/index.html
           insertafter: "^<p><em>Thank you for using nginx."
           line: <p>hello from web server-1"</p>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/92dff050-92c9-489f-8a35-0e625c88b3ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to