Skip to content

Instantly share code, notes, and snippets.

@nuriel77
Last active August 21, 2018 14:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nuriel77/9ba65fe9229aaad472ed1e6a3f0faeab to your computer and use it in GitHub Desktop.
Save nuriel77/9ba65fe9229aaad472ed1e6a3f0faeab to your computer and use it in GitHub Desktop.
Ansible playbook to initialize new undercloud for tripleo
#
# Ansible playbook to prepare the undercloud machine.
# Will preform all steps until custom steps are to be taken --
# which are: providing a custom undercloud.conf and running
# openstack install undercloud command and so on...
# Root SSH access to the remote machine has to be configured.
# Edit vars as necessary.
#
# If this is the first time you are using Ansible on a host,
# make sure to install it (via yum for example), then create
# config file in your working directory (home?) ansible.cfg
# The contents should be something like:
# [defaults]
# inventory = [path-to-inventory-file]
#
# Then create an inventory file containing the name of the
# undercloud machine (instack?)
# To run the playbook you can issue:
# ansible-playbook -v [playbook-file-name.yaml]
#
---
- hosts: all
remote_user: root
gather_facts: False
vars:
ssh_port: 22
openstack_release: newton
ceph_release: jewel
wait_reboot: 900
tasks:
- name: Upgrade all packages
yum: name=* state=latest
- name: Install epel-release
yum: state=latest name=epel-release
- name: Install some packages
yum: state=latest name={{ item }}
with_items:
- perl
- vim
- nano
- wget
- curl
- xauth
- screen
- git
- mlocate
- tcpdump
- lsof
- sysstat
- ntp
- ntpdate
- libselinux-python
- name: Check for reboot hint.
shell: LAST_KERNEL=$(rpm -q --last kernel | perl -pe 's/^kernel-(\S+).*/$1/' | head -1); CURRENT_KERNEL=$(uname -r); if [ "$LAST_KERNEL" != "$CURRENT_KERNEL" ]; then echo 'reboot'; else echo 'no'; fi
ignore_errors: true
register: reboot_hint
- name: "Rebooting ..."
shell: sleep 3 && shutdown -r now
async: 1
poll: 0
ignore_errors: true
when: reboot_hint.stdout.find("reboot") != -1
- name: Wait for machine to restart. If this is baremetal it can take a while...
local_action: wait_for host={{ inventory_hostname }} delay=15 port={{ ssh_port }} timeout={{ wait_reboot }} state=started
when: reboot_hint.stdout.find("reboot") != -1
- name: "Ensure ntp is running (and enable it at boot)"
service: name=ntpd state=started enabled=yes
- name: Add stack user
user:
name: stack
shell: /bin/bash
home: /home/stack
comment: "Undercloud Admin"
- name: Allow 'stack' to have passwordless sudo
lineinfile:
dest: /etc/sudoers.d/stack
create: yes
mode: 0440
state: present
regexp: '^%stack'
line: '%stack ALL=(root) NOPASSWD: ALL'
validate: 'visudo -cf %s'
- name: Download delorean repo
get_url:
url: https://trunk.rdoproject.org/centos7-{{ openstack_release }}/current/delorean.repo
dest: /etc/yum.repos.d/delorean-{{ openstack_release }}.repo
mode: 0644
- name: Download delorean deps repo
get_url:
url: http://trunk.rdoproject.org/centos7-{{ openstack_release }}/delorean-deps.repo
dest: /etc/yum.repos.d/delorean-deps-{{ openstack_release }}.repo
mode: 0644
- name: Install Ceph repo
yum:
state=latest
name=centos-release-ceph-{{ ceph_release }}
enablerepo=extras
- name: Disable gpg check for Ceph repo
replace:
dest: /etc/yum.repos.d/CentOS-Ceph-{{ ceph_release|title }}.repo
regexp: '^gpgcheck=.*'
replace: 'gpgcheck=0'
- name: Download overcloud full image
unarchive:
src: http://buildlogs.centos.org/centos/7/cloud/x86_64/tripleo_images/{{ openstack_release }}/delorean/overcloud-full.tar
dest: /home/stack/
mode: 0644
owner: stack
group: stack
remote_src: yes
- name: Download Ironic python agent images
unarchive:
src: http://buildlogs.centos.org/centos/7/cloud/x86_64/tripleo_images/{{ openstack_release }}/delorean/ironic-python-agent.tar
dest: /home/stack/
mode: 0644
owner: stack
group: stack
remote_src: yes
- name: Install yum plugin prios
yum: state=latest name=yum-plugin-priorities
- name: Install tripleo client
yum: state=latest name=python-tripleoclient
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment