Start provisioning on #OpenStack thru #ansible in a few steps

Boring to provision again and again thru horizon or command-line on your openstack. Well, here you have a refreshing post. Start doing it with ansible.

Step ONE: Prepare your container

Build and prepare your container with ansible and python shade module. First create you Dockerfile with this:

FROM centos:7.3.1611

# Install all packages
RUN yum -y install epel-release && yum clean all
RUN curl "" -o ""
RUN python
RUN yum -y install ansible && yum clean all
RUN yum -y install vim && yum clean all
RUN yum -y install curl && yum clean all
RUN yum -y install git && yum clean all
RUN yum -y install gcc && yum clean all
RUN yum -y install python-devel && yum clean all

# install sdk from nuage
RUN pip install shade

# Generate user shade and his files
RUN yum -y install sudo && useradd -u 65600 -m shade

VOLUME ["/home/shade"]

WORKDIR /home/shade/
USER shade
ENV HOME /home/shade/
CMD ["bash", "--login"]

Now, install docker and build it:

yum -y install docker
systemctl start docker
docker build -t p1nrojas/shade:v1 .
mkdir ~/shade_home
chown 65600:root ~/shade_home
docker run -t -i -v ~/shade_home:/home/shade p1nrojas/shade:v1

Step TWO: import your profile

In my case, I copied my openstack profile called keystone_admin

[root@os-control1 ~(keystone_admin)]# cat keystonerc_admin
export OS_USERNAME=admin
export OS_PASSWORD=admin
export OS_AUTH_URL=
export PS1='[\u@\h \W(keystone_admin)]\$ '

export OS_TENANT_NAME=admin
export OS_REGION_NAME=RegionOne

I created the same file and execute: 'source keystonerc_admin'

You will get this:

bash-4.2$ . keystone_admin
[shade@8975ee6068da ~(keystone_admin)]$

Step THREE: run your playbook

Now it's time to test

[shade@26f0093fec84 ~(keystone_admin)]$ cat os_test.yml

- hosts: localhost

    - name: test
        state: present
        name: test_ansible
        external: true
ansible-playbook os_test.yml
 [WARNING]: provided hosts list is empty, only localhost is available

PLAY [localhost] *****************************************************************************************************************************************************************

TASK [Gathering Facts] ***********************************************************************************************************************************************************
ok: [localhost]

TASK [test] **********************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ***********************************************************************************************************************************************************************
localhost                  : ok=2    changed=1    unreachable=0    failed=0

See ya!

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s

%d bloggers like this: