Archive

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.

https://galaxy.ansible.com/

Advertisements
Categories: ansible Tags: , ,

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: