LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   Vagrant+Ansible playbooks. How to use same playbook on non vagrant provision (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/vagrant-ansible-playbooks-how-to-use-same-playbook-on-non-vagrant-provision-4175486978/)

markotitel 12-05-2013 07:28 AM

Vagrant+Ansible playbooks. How to use same playbook on non vagrant provision
 
Hi, I wanted to try Ansible as deployment tool and have some setup to use with Vagrant. Deployment of that devel VM is working, I wanted to use same playbook on barebone server by manually running
Quote:

ansible-playbook
. That ofcorse cannot work because I was using some setting in playbook that were specific to vagrant. Is it posibile to tell ansible to auto distinct which kind of box it is provisioning?

Here is my playbook file:

Code:

- hosts: main
  remote_user: vagrant
  sudo: yes
  vars:
    app_name: iom
    symfony_root: /vagrant
    locale: en_US.UTF-8
    timezone: UTC
  tasks:
    - name: Setup sudoers for vagrant
      lineinfile: dest=/etc/sudoers
                  regexp='^vagrant ALL=\(ALL\) NOPASSWD:ALL'
                  line="vagrant ALL=(ALL) NOPASSWD:ALL"
                  state=present
                  insertafter=EOF

    - name: Set default language
      template: src=templates/etc/locale.gen dest=/etc/locale.gen

    - name: Install locales
      command: locale-gen

    - name: set locale to {{ locale }}
      command: /usr/sbin/update-locale LANG={{ locale }} LC_ALL={{ locale }} LANGUAGE=en_US:en

    - name: set /etc/localtime to {{ timezone }}
      command: /bin/cp /usr/share/zoneinfo/{{ timezone }} /etc/localtime

    - name: set /etc/timezone to {{ timezone }}
      template: src=templates/timezone dest=/etc/timezone
      notify: update tzdata

    - name: Update apt repo
      action: apt update-cache=yes cache_valid_time=86400

    - name: Install packages
      action: apt name={{ item }} state=installed
      with_items:
        - curl
        - vim
        - git
        - python-apt
        - python-pycurl

    - name: Add key for dotdeb repo
      action: apt_key url='http://www.dotdeb.org/dotdeb.gpg' state=present

Some of this is irrelevant to Vagrant specific setup and also some more code is ommited.

How do you solve this issue? Do you make one extra playbook that you use for production provisioning?

markotitel 12-06-2013 09:00 AM

Let me answer myself :)

There is inventory file where I can define host: ip_address, after that in playbook define which host will do chosen provisioning scheme.


All times are GMT -5. The time now is 03:17 AM.