Reputation: 133
I'm trying to provision a vm with some alias and keep getting permision denied, wondering what the proper way of doing this is:
end of Vagrant file (this works): config.vm.provision :shell, :path => "provision.sh"
in provision.sh: echo "alias alias1=\"some command\"" >> .bashrc
error: /tmp/vagrant-shell: line 6: .bashrc: Read-only file system
Upvotes: 5
Views: 4748
Reputation: 166319
If you're using Ansible Playbooks, you can create a new task role in yml file, in example:
- name: Update bashrc to add foo alias for Vagrant user
lineinfile:
dest=/home/vagrant/.bashrc
line="alias foo='bar'"
regexp="^alias foo"
owner=vagrant
state=present
insertafter=EOF
create=True
then run the ansible script (sudo ansible-playbook foo.yml
) from your vagrant provision file.
Alternatively use ex
to append alias to the end of the file:
ex -s +':$s@$@\ralias foo=bar@' -cwq /etc/bash.bashrc
See also: How to append some line at the end of the file only if it's not there yet? in Ex
Upvotes: 0
Reputation: 53703
CoreOS has some specific issue about that as by default ~/.bashrc
is symlinked into /usr
(read-only folder).
You can replace the symlink with a copy of the file and then make edits. Something like this in your provision.sh
would do the trick:
cp $(readlink .bashrc) .bashrc.new && mv .bashrc.new .bashrc
echo "alias alias1=\"some command\"" >> .bashrc
I cannot test as I do not have CoreOS box but it should work
Upvotes: 1
Reputation: 133
this ended up being a coreOS issue (I think it has to do with it's read only file system or something like that, I should have mentioned it in the question), I ended up using Ubuntu for my VM (I'm only using the VM to run Docker) and the above command in your comment/my original question ended up working.
Upvotes: 2