Issue
I’ve the following Ansible task to install Dart:
---
# Install Dart
# Based on:
# - https://www.dartlang.org/install/linux#using-apt-get
# - https://github.com/jgrowl/ansible-dart
- name: install apt-transport-https required by Dart
apt: pkg=apt-transport-https update_cache=yes state=latest
# Get the Google Linux package signing key.
- apt_key: url=https://dl-ssl.google.com/linux/linux_signing_key.pub state=present
# Set up the location of the stable repository.
- name: download dart source list
get_url: url=https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list dest=/etc/apt/sources.list.d/dart_stable.list mode=0644
# Set up for the dev channel
# Before running this command, follow the instructions in
# "Set up for the stable channel".
#$ sudo sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_unstable.list > /etc/apt/sources.list.d/dart_unstable.list'
- apt: name=dart update_cache=yes state=present
- name: Add dart and tools to PATH
template: src=dart.sh.j2 dest=/etc/profile.d/dart.sh owner=root group=root mode=0655
notify:
- install stagehand
It seems to install correctly Dart. The problem is when I notify install stagehand
at the end. That handler is as follows
---
# Called after installing Dart to install Dart's package stagehand
- name: install stagehand
shell: pub global activate stagehand
But I keep receiving the following errors:
...
TASK [install stagehand] *******************************************************
fatal: [default]: FAILED! => {"changed": true, "cmd": "pub global activate stagehand", "delta": "0:00:00.001392", "end": "2017-02-13 02:03:06.679762", "failed": true, "rc": 127, "start": "2017-02-13 02:03:06.678370", "stderr": "/bin/sh: 1: pub: not found", "stdout": "", "stdout_lines": [], "warnings": []}
to retry, use: --limit
@/Users/X/Desktop/path_to_project/provision/ansible/playbook.retry
which is very strange because if I try to login to the Vagrant VM using vagrant ssh
and I type pub
, the packager manager of Dart is installed!
Since I’m very new to Ansible as well as all other technologies that I’m using, this could also be a problem caused becaused I still don’t know exactly how Ansible works.
Edit
This the file (i.e. dart.sh.j2
) that theoretically should export also pub
:
# Add vendor binaries to the path
PATH=$PATH:/usr/lib/dart/bin
Edit 2
Here’s the Vagrantfile
(as requested):
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network :forwarded_port, guest: 80, host: 4567
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
# Run Ansible from the Vagrant Host
config.vm.provision "ansible" do |ansible|
ansible.playbook = "provision/ansible/playbook.yml"
end
end
Solution
Based on the answer by SztupY, I managed to activate Dart’s package stagehand
inside the Vagrant VM, ubuntu/trusty64
.
These are the tools I used with their corresponding versions (in case somebody ends up in this post because of a similar problem):
+=================+============================+=========================================================+
| Tool | Version | Comments |
+=================+============================+=========================================================+
| Ansible | 2.2.1.0 | configured module search path = Default w/o overrides |
+-----------------+----------------------------+---------------------------------------------------------+
| Vagrant | 1.9.1 | |
+-----------------+----------------------------+---------------------------------------------------------+
| ubuntu/trusty64 | (virtualbox, 20170202.1.0) | |
+-----------------+----------------------------+---------------------------------------------------------+
| ansible-dart | | Source: https://github.com/nbro/ansible-dart |
+-----------------+----------------------------+---------------------------------------------------------+
I placed the downloaded folder of the Github project ansible-dart
under the folder roles
, which is under the main folder of the provision folder (which in my case I called provision/ansible
), which contains the playbook.yml
file.
- name: provisioning project...
hosts: all
roles:
- { role: ansible-dart, when: ansible_os_family == "Debian", become: true }
tasks:
- name: "add .pub-cache to PATH"
lineinfile:
dest: /home/vagrant/.profile
line: 'PATH=$PATH:/home/vagrant/.pub-cache/bin'
- name: activate Dart's package 'stagehand'
shell: bash -lc "pub global activate stagehand"
Answered By – nbro
Answer Checked By – David Goodson (FlutterFixes Volunteer)