“vagrant provision” works, but I cannot send an ad-hoc command with Ansible

后端 未结 2 1219
南方客
南方客 2021-01-14 17:38

I have set up a machine with Vagrant, and created a basic Ansible playbook for it. Everything works as expected when I run

vm-abla> vagrant provision
         


        
2条回答
  •  野的像风
    2021-01-14 17:59

    As @mascip already self-answered, you need to tell ansible: inventory_file, ssh_user and ssh_private_key. (I don't think the -c ssh setting is needed.)

    The "elegant way" is to put all those settings into a project-specific ansible.cfg file. Then you can just run ansible jon -a "echo 'TEST'".

    One "gotcha" is that ansible.cfg must be in the same directory as where you're running the ansible command. I like to put ansible.cfg under my ansible directory, so that means I need to cd there first. If you want to run ansible from your project root, then put ansible.cfg there instead (and adjust the relative paths in the sample config file below).

    ansible.cfg:

    [defaults]
    
    remote_user = vagrant
    private_key_file = ~/.vagrant.d/insecure_private_key
    
    # aka inventory file
    hostfile = ../.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory
    

提交回复
热议问题