Home > ansible > Ansible – Interactive scripts

Ansible – Interactive scripts

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

Advertisements
Categories: ansible Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: