Ansible & Vagrant: deploy in local and production with same playbook -
i've been working in recipe vagrant+virtualbox+ansible lately. have issues want reuse code of recipe able provision not local staging , production environment. playbook is:
- hosts: sudo: true pre_tasks: roles: - common - webserver - database - php post_tasks:
and vagrantfile
# -*- mode: ruby -*- # vi: set ft=ruby : vagrantfile_api_version = "2" vagrant.configure(vagrantfile_api_version) |config| config.vm.box = "ubuntu/precise64" config.vm.network "private_network", ip: "10.10.10.101" config.vm.synced_folder ".", "/vagrant", type: "nfs" config.vm.provider "virtualbox" |vb| vb.gui = true vb.customize ["modifyvm", :id, "--memory", "512"] vb.name = "testing" end config.vm.provision :ansible |ansible| ansible.playbook = "playbook.yml" ansible.limit = "local" ansible.inventory_path = "./inventory" end end
so happens? if run
$ vagrant
everything works fine if run
$ ansible-playbook -i inventory playbook.yml --limit production
(where production group in inventory remote ip on ovh)
it fails because playbook need
user:root
parameter, if put parameter on playbook, fails when run
$ vagrant provision
i know making yml local , remote finish issue, prefer more elegant solution.
any ideas?
thanks
you can customize ssh user per host in inventory using group vars:
in group_vars/local:
ansible_ssh_user: vagrant
in group_vars/production:
ansible_ssh_user: root
also consider using separate inventory files vagrant , production. doesn't allow run things on both envs @ once, that's hardly common use case, , it's safer.
Comments
Post a Comment