Archive for the ‘ansible’ Category

Ansible – Interactive scripts

May 20, 2016 Leave a comment

Working with interactive scripts in Ansible 2. I need to change the shell from bash to zsh. Using the command chsh -s /usr/bin/zsh will prompt the user for their password. I am running this command on a vagrant box.

Use expect.

This is what I added to my existing ansible script.

– name: “Install python pip”
become_user: root
apt: name=python-pip state=present

# expect needs pexpect to work.
– pip: name=pexpect version=3.3
become_user: root

– expect:
command: chsh -s /usr/bin/zsh
Password: vagrant


Categories: ansible Tags: ,

Running vim commands on the cli

May 4, 2016 Leave a comment

I am trying to configure ansible to install some vim plugins. When doing this manually the steps are you git clone the repo, then run a vim command. How to do the same when using a script?

From the vim manual


-c {command}
{command} will be executed after the first file has been read. {command} is interpreted as an Ex command. If the {command} contains spaces it must
be enclosed in double quotes (this depends on the shell that is used). Example: Vim “+set si” main.c
Note: You can use up to 10 “+” or “-c” commands.

–cmd {command}
Like using “-c”, but the command is executed just before processing any vimrc file. You can use up to 10 of these commands, independently from “-c”

Some examples:

vim "+PromptlineSnapshot ~/ lightline" "+q"


vim -c "PromptlineSnapshot ~/ lightline" -c "q"


Categories: ansible, bash, vim Tags: