2

Is there a method to using Ansible's start-at-task from within a Vagrantfile? I want to specify the exact task to start at for debugging purposes. I realize host vars will be missing, this is fine. Other similar questions don't seem to be asking exactly this.

One idea is to set an ENV_VAR, Vagrant populates that and passes it to the playbook. ie:

# export START_TASK='task-name'
# Run: "vagrant provision --provision-with resume"

  config.vm.provision "resume", type: "ansible_local" do |resume|
    resume.playbook = "playbooks/playbook.yml --start-at-task=ENV['START_TASK']"
  end

The playbook command doesn't parse the env_var like that but I'm essentially trying to run that command. I'm basically just trying to parse that env_var and pass it to Vagrant ansible provisioner.

Note: @retry on the playbook only re-runs the entire failed playbook for that single host not just a single command so that's not a solution.

Michael
  • 1,577
  • 1
  • 18
  • 33
  • Please use a clear example of what you want to achieve instead of dumping your thoughts. It's unclear what is your objective, what is your imagined workaround ("*one idea is...*"), what "*other questions*" you refer to, what does `@retry` have to do with it all. – techraf Apr 05 '18 at 23:52
  • That's what the code block is, exactly what I want. – Michael Apr 06 '18 at 00:00
  • @retry is mentioned in most all other similar Vagrant + ansible retry a task type questions. Adding that is useful to save people time. – Michael Apr 06 '18 at 00:01

1 Answers1

4

Just needed to add the following, which I couldn't find anywhere in Vagrant's documentation.

resume.start_at_task = ENV['START_AT_TASK']
Michael
  • 1,577
  • 1
  • 18
  • 33
  • For anyone landing on this question. This is now documented on https://www.vagrantup.com/docs/provisioning/ansible_common.html – Augusto Jan 23 '19 at 05:40