Vagrant with Ansible

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Vagrant with Ansible

Ivan Adji-Krstev
Hi all, 

I want to use Ansible during the creation of Vagrant Box or Vagrant UP. So i have the following configuration about it

config.vm.provision "ansible_local" do |ansible|
  ansible.extra_vars = { HOSTS: "vagrantbox" }
  ansible.playbook = "/vagrant/httpd.yaml"    
end
And in the httpd.yaml file i have this
---
- hosts: localhost
  vars:
    http_port: 80
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: name=httpd state=latest
  - name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
 
So when i run the Vagrant up from the directory where i have Vagrant file and httpd.yaml file i got this error from Ansible
    default: Running ansible-playbook...
PLAY [localhost] ***************************************************************
skipping: no hosts matched
PLAY RECAP *********************************************************************

Now the interesting part is that when i do vagrant ssh and try to execute the same playbook, it works. It does not give me a problem. 
Yes this is ansible executing the playbook locally for testing.
 Also i want to use ansible-pull but still have the same problem.  

Its not the problem installation of the httpd i know i can do it with vagrant, i want to do something with Ansible and i start this simple test. 

Can someone tell me how can i force ansible to work with localhost. 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/44fac18b-4c28-407b-9b7e-c1a82fdf825a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Vagrant with Ansible

Jamie Jackson
Maybe you could take a step back and explain why you want to use (or test) against localhost? You mentioned that you wanted to use ansible during vagrant up, for instance, so I'm having trouble understanding why you'd want to provision your host instead of your guest.

I'm provisioning a guest so I went with the simple `hosts: all` in the playbook.yml

Also, I don't know if you'll need it or not, but in my Vagrantfile, I have:


    # Disable the new default behavior introduced in Vagrant 1.7, to
    # ensure that all Vagrant machines will use the same SSH key pair.
    config.ssh.insert_key = false






On Tue, Oct 10, 2017 at 11:12 AM, Ivan Adji-Krstev <[hidden email]> wrote:
Hi all, 

I want to use Ansible during the creation of Vagrant Box or Vagrant UP. So i have the following configuration about it

config.vm.provision "ansible_local" do |ansible|
  ansible.extra_vars = { HOSTS: "vagrantbox" }
  ansible.playbook = "/vagrant/httpd.yaml"    
end
And in the httpd.yaml file i have this
---
- hosts: localhost
  vars:
    http_port: 80
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: name=httpd state=latest
  - name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
 
So when i run the Vagrant up from the directory where i have Vagrant file and httpd.yaml file i got this error from Ansible
    default: Running ansible-playbook...
PLAY [localhost] ***************************************************************
skipping: no hosts matched
PLAY RECAP *********************************************************************

Now the interesting part is that when i do vagrant ssh and try to execute the same playbook, it works. It does not give me a problem. 
Yes this is ansible executing the playbook locally for testing.
 Also i want to use ansible-pull but still have the same problem.  

Its not the problem installation of the httpd i know i can do it with vagrant, i want to do something with Ansible and i start this simple test. 

Can someone tell me how can i force ansible to work with localhost. 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/44fac18b-4c28-407b-9b7e-c1a82fdf825a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CA%2BonWPcA0eH5J2Oy5Ea-i1a_1suyYx%2BOgrhG8rMyQ_9ovDW2LA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Vagrant with Ansible

Ivan Adji-Krstev
Hi Jamie, 

What i want to do is, to have is when the VagrantBox is up or bring up, from the inside of the box, i want Ansibe to make pull or execute the playbook.yml file on the VM (VagrantBox/Guest). I'm using Vagrant to build the VM, and i want Ansible to play role as Pull or to execute locally the playbook. I'll take the ssh.insert_key parameter, but i'm having problem to execute this playbook.yml file locally which is working if i execute after the VM is up and running but not when i build the VM. 

I think the problem is that when you build the Vagrant Box, the Ansible take the default host file and search for the localhost information, instead of the playbook.yml or something. Its executing with parameters or something similar. 

I try to use host all but i got this error:

    default: Running ansible-playbook...
PLAY [all] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [default]
TASK [ensure apache is at the latest version] **********************************
fatal: [default]: FAILED! => {"changed": true, "failed": true, "msg": "You need to be root to perform this command.\n", "rc": 1, "results": ["Loaded plugins: fastestmirror\n"]}
        to retry, use: --limit @/vagrant/httpd.retry
PLAY RECAP *********************************************************************
default                    : ok=1    changed=0    unreachable=0    failed=1
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

Also the main part here is to use Ansible-Pull which pull the yaml file from Git Repo and then execute locally. But if i can work around with this ill work around with pull to. 

On Tuesday, October 10, 2017 at 10:34:21 PM UTC+2, Jamie Jackson wrote:
Maybe you could take a step back and explain why you want to use (or test) against localhost? You mentioned that you wanted to use ansible during vagrant up, for instance, so I'm having trouble understanding why you'd want to provision your host instead of your guest.

I'm provisioning a guest so I went with the simple `hosts: all` in the playbook.yml

Also, I don't know if you'll need it or not, but in my Vagrantfile, I have:


    # Disable the new default behavior introduced in Vagrant 1.7, to
    # ensure that all Vagrant machines will use the same SSH key pair.
    # See <a href="https://github.com/mitchellh/vagrant/issues/5005" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues%2F5005\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFcB8hYOvPtFu4OeuRHmdNHHTgCLQ&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues%2F5005\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFcB8hYOvPtFu4OeuRHmdNHHTgCLQ&#39;;return true;">https://github.com/mitchellh/vagrant/issues/5005
    config.ssh.insert_key = false






On Tue, Oct 10, 2017 at 11:12 AM, Ivan Adji-Krstev <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mmc-tVggBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">iadji...@...> wrote:
Hi all, 

I want to use Ansible during the creation of Vagrant Box or Vagrant UP. So i have the following configuration about it

config.vm.provision "ansible_local" do |ansible|
  ansible.extra_vars = { HOSTS: "vagrantbox" }
  ansible.playbook = "/vagrant/httpd.yaml"    
end
And in the httpd.yaml file i have this
---
- hosts: localhost
  vars:
    http_port: 80
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: name=httpd state=latest
  - name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
 
So when i run the Vagrant up from the directory where i have Vagrant file and httpd.yaml file i got this error from Ansible
    default: Running ansible-playbook...
PLAY [localhost] ***************************************************************
skipping: no hosts matched
PLAY RECAP *********************************************************************

Now the interesting part is that when i do vagrant ssh and try to execute the same playbook, it works. It does not give me a problem. 
Yes this is ansible executing the playbook locally for testing.
 Also i want to use ansible-pull but still have the same problem.  

Its not the problem installation of the httpd i know i can do it with vagrant, i want to do something with Ansible and i start this simple test. 

Can someone tell me how can i force ansible to work with localhost. 

--
This mailing list is governed under the HashiCorp Community Guidelines - <a href="https://www.hashicorp.com/community-guidelines.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.hashicorp.com%2Fcommunity-guidelines.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGHa_CaKfZaJiwbkUndUQbVGlQCDw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.hashicorp.com%2Fcommunity-guidelines.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGHa_CaKfZaJiwbkUndUQbVGlQCDw&#39;;return true;">https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: <a href="https://github.com/mitchellh/vagrant/issues" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHxcA5DuHlQlPInMi_k1Pz4pMNqNw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fgithub.com%2Fmitchellh%2Fvagrant%2Fissues\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHxcA5DuHlQlPInMi_k1Pz4pMNqNw&#39;;return true;">https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="mmc-tVggBAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">vagrant-up+...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/vagrant-up/44fac18b-4c28-407b-9b7e-c1a82fdf825a%40googlegroups.com?utm_medium=email&amp;utm_source=footer" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/44fac18b-4c28-407b-9b7e-c1a82fdf825a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/msgid/vagrant-up/44fac18b-4c28-407b-9b7e-c1a82fdf825a%40googlegroups.com?utm_medium\x3demail\x26utm_source\x3dfooter&#39;;return true;">https://groups.google.com/d/msgid/vagrant-up/44fac18b-4c28-407b-9b7e-c1a82fdf825a%40googlegroups.com.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/0b65e7f3-5c6c-4d0a-a104-4e69bf904113%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Vagrant with Ansible

Jamie Jackson
Sorry, I just realized you're using the "ansible_local" provisioner; I forgot that existed. I've only used the "ansible" provisioner, so that's why I was confused. Hopefully, someone with actual "ansible_local" experience can help.

On Tue, Oct 10, 2017 at 6:12 PM, Ivan Adji-Krstev <[hidden email]> wrote:
Hi Jamie, 

What i want to do is, to have is when the VagrantBox is up or bring up, from the inside of the box, i want Ansibe to make pull or execute the playbook.yml file on the VM (VagrantBox/Guest). I'm using Vagrant to build the VM, and i want Ansible to play role as Pull or to execute locally the playbook. I'll take the ssh.insert_key parameter, but i'm having problem to execute this playbook.yml file locally which is working if i execute after the VM is up and running but not when i build the VM. 

I think the problem is that when you build the Vagrant Box, the Ansible take the default host file and search for the localhost information, instead of the playbook.yml or something. Its executing with parameters or something similar. 

I try to use host all but i got this error:

    default: Running ansible-playbook...
PLAY [all] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [default]
TASK [ensure apache is at the latest version] **********************************
fatal: [default]: FAILED! => {"changed": true, "failed": true, "msg": "You need to be root to perform this command.\n", "rc": 1, "results": ["Loaded plugins: fastestmirror\n"]}
        to retry, use: --limit @/vagrant/httpd.retry
PLAY RECAP *********************************************************************
default                    : ok=1    changed=0    unreachable=0    failed=1
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.

Also the main part here is to use Ansible-Pull which pull the yaml file from Git Repo and then execute locally. But if i can work around with this ill work around with pull to. 

On Tuesday, October 10, 2017 at 10:34:21 PM UTC+2, Jamie Jackson wrote:
Maybe you could take a step back and explain why you want to use (or test) against localhost? You mentioned that you wanted to use ansible during vagrant up, for instance, so I'm having trouble understanding why you'd want to provision your host instead of your guest.

I'm provisioning a guest so I went with the simple `hosts: all` in the playbook.yml

Also, I don't know if you'll need it or not, but in my Vagrantfile, I have:


    # Disable the new default behavior introduced in Vagrant 1.7, to
    # ensure that all Vagrant machines will use the same SSH key pair.
    config.ssh.insert_key = false






On Tue, Oct 10, 2017 at 11:12 AM, Ivan Adji-Krstev <[hidden email]> wrote:
Hi all, 

I want to use Ansible during the creation of Vagrant Box or Vagrant UP. So i have the following configuration about it

config.vm.provision "ansible_local" do |ansible|
  ansible.extra_vars = { HOSTS: "vagrantbox" }
  ansible.playbook = "/vagrant/httpd.yaml"    
end
And in the httpd.yaml file i have this
---
- hosts: localhost
  vars:
    http_port: 80
  remote_user: root
  tasks:
  - name: ensure apache is at the latest version
    yum: name=httpd state=latest
  - name: ensure apache is running (and enable it at boot)
    service: name=httpd state=started enabled=yes
 
So when i run the Vagrant up from the directory where i have Vagrant file and httpd.yaml file i got this error from Ansible
    default: Running ansible-playbook...
PLAY [localhost] ***************************************************************
skipping: no hosts matched
PLAY RECAP *********************************************************************

Now the interesting part is that when i do vagrant ssh and try to execute the same playbook, it works. It does not give me a problem. 
Yes this is ansible executing the playbook locally for testing.
 Also i want to use ansible-pull but still have the same problem.  

Its not the problem installation of the httpd i know i can do it with vagrant, i want to do something with Ansible and i start this simple test. 

Can someone tell me how can i force ansible to work with localhost. 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vagrant-up+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/44fac18b-4c28-407b-9b7e-c1a82fdf825a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/0b65e7f3-5c6c-4d0a-a104-4e69bf904113%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CA%2BonWPdNZ%2B6kdB5uON9TmFqrDa5JNyr4%3DkYjaKQmo65TKK%3DJWg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Vagrant with Ansible

Alvaro Miranda Aguilera
In reply to this post by Ivan Adji-Krstev
what happens if you use:

  ansible.playbook = "httpd.yaml" 

instead 

  ansible.playbook = "/vagrant/httpd.yaml" 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0exB0f%2BZwgNo0XS9t-sCN97n9mivb5czHNb6whoSMEbG7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Vagrant with Ansible

Ivan Adji-Krstev
Hi Alvaro, 
This seems to work. I have problem with ansible yaml file too but i have fixed. 
Now my question is, how can i use ansible-pull ( https://docs.ansible.com/ansible/2.4/ansible-pull.html ) with Vagrant file. 
Instead of Ansible playbook to use ansible-pull which pull the yaml file from git and execute it locall.

On Wednesday, October 11, 2017 at 10:11:23 AM UTC+2, Alvaro Miranda Aguilera wrote:
what happens if you use:

  ansible.playbook = "httpd.yaml" 

instead 

  ansible.playbook = "/vagrant/httpd.yaml" 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/7d37f83f-18eb-4b53-ba13-4015c35ac517%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Vagrant with Ansible

Alvaro Miranda Aguilera
I don't think that is supported yet.

so the best would do some shell scripts at the moment.

Seems very useful, you way want to open some issue on the tracker and maybe someone can help integrate it.

Alvaro

On Wed, Oct 11, 2017 at 6:54 PM, Ivan Adji-Krstev <[hidden email]> wrote:
Hi Alvaro, 
This seems to work. I have problem with ansible yaml file too but i have fixed. 
Now my question is, how can i use ansible-pull ( https://docs.ansible.com/ansible/2.4/ansible-pull.html ) with Vagrant file. 
Instead of Ansible playbook to use ansible-pull which pull the yaml file from git and execute it locall.

On Wednesday, October 11, 2017 at 10:11:23 AM UTC+2, Alvaro Miranda Aguilera wrote:
what happens if you use:

  ansible.playbook = "httpd.yaml" 

instead 

  ansible.playbook = "/vagrant/httpd.yaml" 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/7d37f83f-18eb-4b53-ba13-4015c35ac517%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Alvaro

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/vagrant/issues
IRC: #vagrant on Freenode
---
You received this message because you are subscribed to the Google Groups "Vagrant" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/vagrant-up/CAHqq0eyJext0wY2EAKUSdtDhAarTgVf1WTiSdmBfWt-qcpLfAw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.