Archive

Archive for the ‘ansible’ Category

Ansible – Interactive scripts

May 20, 2016 Leave a comment

Problem:
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.

Solution:
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
responses:
Password: vagrant

Source:
http://docs.ansible.com/ansible/expect_module.html
http://docs.ansible.com/ansible/pip_module.html

Categories: ansible Tags: ,

Running vim commands on the cli

May 4, 2016 Leave a comment

Problem:
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?

Solution:
From the vim manual

+{command}

-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”
commands.

Some examples:


vim "+PromptlineSnapshot ~/.shell_prompt.sh lightline" "+q"

or


vim -c "PromptlineSnapshot ~/.shell_prompt.sh lightline" -c "q"

Source:
http://stackoverflow.com/questions/12834370/run-vim-command-from-commandline

Categories: ansible, bash, vim Tags: