Archive for the ‘ansible’ Category

Ansible Galaxy

July 27, 2017 Leave a comment

Ansible Galaxy is Ansible’s official community hub for sharing Ansible roles. A role is the Ansible way of bundling automation content and making it reusable.

If you’re not familiar with the Ansible role concept, think of include files used in a programming language. An include file allows the programmer to organize code into reusable modules. Code can be organized into smaller files and grouped by subject matter or function. These discrete pieces of code can then be included as needed into larger programs like building blocks.

A role is similar. Instead of creating giant playbooks with hundreds of tasks we can use roles to organize tasks, breaking them apart into smaller more discrete units of work. But a role is more than just an include file. A role is all the tasks, variables and handlers needed to complete the unit of work. This allows a role to be completely self contained or encapsulated and completely reusable.

Using roles also allows us to think about node configuration in terms of modeling. For example, given a set of nodes that should be web servers we can simply apply a web server role to them. We don’t have to think about or write all the tasks needed to configure web servers. All the details are already encapsulated in a web server role – a role you downloaded from Galaxy.

Categories: ansible Tags: , ,

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: