ahelal / kitchen-ansiblepush

test-kitchen plugin to use ansible in push mode
41 stars 22 forks source link

how to add localhost as inventory file #50

Closed bob2build closed 5 years ago

bob2build commented 5 years ago

kitchen-ansible-inventory does not include localhost. So I am unable to run any commands on the controller node. Is there any configuration to add localhost name in the inventory?

$ kitchen-ansible-inventory
{
  "all": [
    "default-bento-centos-74",
    "bento-centos-74"
  ],
  "_meta": {
    "hostvars": {
      "default-bento-centos-74": {
        "ansible_ssh_host": "127.0.0.1",
        "ansible_ssh_port": "2222",
        "ansible_ssh_private_key_file": "/Users/anmanoha/development/cloudtrust/ironhide/.kitchen/kitchen-vagrant/default-bento-centos-74/.vagrant/machines/default/virtualbox/private_key"
      },
      "bento-centos-74": {
        "ansible_ssh_host": "127.0.0.1",
        "ansible_ssh_port": "2222",
        "ansible_ssh_private_key_file": "/Users/anmanoha/development/cloudtrust/ironhide/.kitchen/kitchen-vagrant/default-bento-centos-74/.vagrant/machines/default/virtualbox/private_key"
      }
    }
  }
}
ahelal commented 5 years ago

you must use ansible delegate_to: 127.0.0.1 and/or connection=local

bob2build commented 5 years ago

I didn't quite get how delegate_to: 127.0.0.1 works, I managed to make this work by creating a static file local_inventory.yaml in root directory

all:
  hosts:
    localhost:
      connection: local
      ansible_python_interpreter: /usr/bin/python

and passed raw_arguments: "--inventory-file=test/ansible/local_inventory.yaml" in kitchen.yml

Thanks for the info @ahelal. This plugin works great. I infact use kitchen-ansiblepush to upload cookbooks tar.gz file to remove servers and run chef-solo. It is counter intuitive, however, kitchen is really slow to converge cookbooks since it uploads 1 file at a time.

avishayil commented 5 years ago

Hi @bob2build @ahelal Is this solution going to work with the internal inventory file that the plugin creates to connect to the created machine during converge?

bob2build commented 5 years ago

@avishayil I only tried with localhost. However, I believe this should allow you to add additional hosts on top of existing hosts created by vagrant.

avishayil commented 5 years ago

I'm working with kitchen ec2 driver, i'll try and let anyone know here in case someone else searches this. Thanks!