Skip to content

Commit

Permalink
Update create-ansible-tower.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
George Adams committed Jul 10, 2018
1 parent 63f0957 commit 0ecf98d
Show file tree
Hide file tree
Showing 3 changed files with 165 additions and 168 deletions.
162 changes: 1 addition & 161 deletions ansible/playbooks/create-ansible-tower.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
roles:
- bootstrap
- package-upgrade
- ansible-tower

pre_tasks:
- name: check if secrets are properly set
Expand All @@ -19,164 +20,3 @@
with_items:
- awx_password
- awx_org

tasks:

- name: set hostname
hostname: name="ansible.nodejs.org"

- name: update /etc/hosts file - 127.0.0.1
lineinfile:
dest: /etc/hosts
regexp: "^(.*)127.0.0.1 ansible.nodejs.org(.*)$"
line: "127.0.0.1 ansible.nodejs.org ansible-tower"
state: present
backup: yes

- name: import docker gpg key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present

- name: import docker apt repostory
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
state: present

- name: import ansible apt repostory
apt_repository:
repo: ppa:ansible/ansible
state: present

- name: install apt dependencies
apt:
name: "{{ packages }}"
update_cache: yes
vars:
packages:
- ansible
- apt-transport-https
- binutils
- ca-certificates
- curl
- dkms
- docker-ce
- gcc
- git
- make
- patch
- python-pip
- python3-pip
- software-properties-common
- vim

- name: install pip dependencies
pip:
name: "{{ packages }}"
vars:
packages:
- ansible-tower-cli
- django
- docker
- pexpect

- name: start the docker service
service:
name: docker
state: started

- name: create /opt/awx_install_files
file: path=/opt/awx_install_files state=directory

- name: clone awx github repository
git:
repo: https://github.com/ansible/awx.git
dest: /opt/awx_install_files/awx
force: yes

- name: run awx install files, this can take ~20 mins
command: chdir=/opt/awx_install_files/awx/installer/ ansible-playbook -i inventory install.yml

- name: change awx admin password
expect:
command: docker exec -it awx_task awx-manage changepassword admin
responses:
(?i)password: "{{ awx_password }}"

#TODO: change this to be https://ansible.nodejs.org and remove verify_ssl
- name: create /root/.tower_cli.cfg
blockinfile:
path: /root/.tower_cli.cfg
block: |
host: 169.62.77.235
username: admin
password: {{ awx_password }}
verify_ssl: False
create: yes
mode: 0700

- name: delete Default organization created at install
command: tower-cli organization delete Default

- name: create new organization (set in hosts file)
command: tower-cli organization create --name {{ awx_org }}

- name: create new team belonging to organization
command: tower-cli team create --name {{ awx_org }} --organization {{ awx_org }}

- name: add nodejs/build repo to AWX
command: tower-cli project create --organization {{ awx_org }} --name nodejs/build --scm-type git --scm-url https://github.com/nodejs/build --scm-branch master --scm-update-on-launch true

- name: create inventory
command: tower-cli inventory create --organization {{ awx_org }} --name nodejs_inventory_github

- name: create automate fetching inventory from inventory.yml
command: tower-cli inventory_source create --name github --inventory nodejs_inventory_github --source scm --source-project nodejs/build --source-path ansible/plugins/inventory/nodejs_yaml.py --overwrite true --overwrite-vars true --update-on-launch true

- name: prevent ubuntu deleting /tmp folder on reboot
command: echo > /etc/init/mounted-tmp.conf

- name: patch ubuntu weekly at 5 Sundays
cron:
name: "apt-get update"
minute: "0"
hour: "5"
weekday: "sun"
job: "apt-get update"

- name: upgrade ubuntu weekly at 5:15 Sundays
cron:
name: "apt-get -y upgrade"
minute: "15"
hour: "5"
weekday: "sun"
job: "apt-get -y upgrade"

- name: create /backup
file: path=/backup state=directory

- name: setup Backups for AWX docker containers
blockinfile:
path: /backup/backup_docker_AWX.sh
block: |
DATE=`date +%m-%d-%Y`
# Create Tar backups from the containers
docker save -o /backup/awx_test_backup_$DATE.tar ansible/awx_task
docker save -o /backup/awx_web_backup_$DATE.tar ansible/awx_web
docker save -o /backup/rabbitmq_backup_$DATE.tar rabbitmq
docker save -o /backup/postgres_backup_$DATE.tar postgres
docker save -o /backup/memcached_backup_$DATE.tar memcached
tar -cvf /backup/postgres_tmp_backup_$DATE.tar /tmp/pgdocker
create: yes

- name: make backup_docker_AWX.sh executable
command: chmod +x /backup/backup_docker_AWX.sh

- name: backup AWX's docker containers weekly at 5am on Mondays
cron:
name: "/backup/backup_docker_AWX.sh"
minute: "0"
hour: "5"
weekday: "mon"
job: "/backup/backup_docker_AWX.sh"
11 changes: 4 additions & 7 deletions ansible/plugins/inventory/nodejs_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import yaml
import os
import sys
from os import path


valid = {
Expand Down Expand Up @@ -107,11 +108,7 @@ def main():
hostname = '{}-{}{}{}'.format(host_type, provider_name,
delimiter, host)

# no point in adding windows servers for now
if 'win' in hostname:
continue
else:
export[host_type]['hosts'].append(hostname)
export[host_type]['hosts'].append(hostname)

c = {}

Expand All @@ -137,8 +134,8 @@ def main():
if 'alias' in metadata:
c.update({'alias': metadata['alias']})

if 'win' in hostname:
c.update({'is_win': True})
if 'vs' in metadata:
c.update({'vs': metadata['vs']})

# add specific options from config
for option in ifilter(lambda s: s.startswith('hosts:'),
Expand Down
160 changes: 160 additions & 0 deletions ansible/roles/ansible-tower/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
---

- name: set hostname
hostname: name="ansible.nodejs.org"

- name: update /etc/hosts file - 127.0.0.1
lineinfile:
dest: /etc/hosts
regexp: "^(.*)127.0.0.1 ansible.nodejs.org(.*)$"
line: "127.0.0.1 ansible.nodejs.org ansible-tower"
state: present
backup: yes

- name: import docker gpg key
apt_key:
url: https://download.docker.com/linux/ubuntu/gpg
state: present

- name: import docker apt repostory
apt_repository:
repo: deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable
state: present

- name: import ansible apt repostory
apt_repository:
repo: ppa:ansible/ansible
state: present

- name: install apt dependencies
apt:
name: "{{ packages }}"
update_cache: yes
vars:
packages:
- ansible
- apt-transport-https
- binutils
- ca-certificates
- curl
- dkms
- docker-ce
- gcc
- git
- make
- patch
- python-pip
- python3-pip
- software-properties-common
- vim

- name: install pip dependencies
pip:
name: "{{ packages }}"
vars:
packages:
- ansible-tower-cli
- django
- docker
- pexpect

- name: start the docker service
service:
name: docker
state: started

- name: create /opt/awx_install_files
file: path=/opt/awx_install_files state=directory

- name: clone awx github repository
git:
repo: https://github.com/ansible/awx.git
dest: /opt/awx_install_files/awx
force: yes

- name: run awx install files, this can take ~20 mins
command: chdir=/opt/awx_install_files/awx/installer/ ansible-playbook -i inventory install.yml

- name: change awx admin password
expect:
command: docker exec -it awx_task awx-manage changepassword admin
responses:
(?i)password: "{{ awx_password }}"

#TODO: change this to be https://ansible.nodejs.org and remove verify_ssl
- name: create /root/.tower_cli.cfg
blockinfile:
path: /root/.tower_cli.cfg
block: |
host: http://169.62.77.235
username: admin
password: {{ awx_password }}
verify_ssl: False
create: yes
mode: 0700

- name: delete Default organization created at install
command: tower-cli organization delete Default

- name: create new organization (set in hosts file)
command: tower-cli organization create --name {{ awx_org }}

- name: create new team belonging to organization
command: tower-cli team create --name {{ awx_org }} --organization {{ awx_org }}

- name: add nodejs/build repo to AWX
command: tower-cli project create --organization {{ awx_org }} --name nodejs/build --scm-type git --scm-url https://github.com/nodejs/build --scm-branch master --scm-update-on-launch true

- name: create inventory
command: tower-cli inventory create --organization {{ awx_org }} --name nodejs_inventory_github

- name: create automate fetching inventory from inventory.yml
command: tower-cli inventory_source create --name github --inventory nodejs_inventory_github --source scm --source-project nodejs/build --source-path ansible/plugins/inventory/nodejs_yaml.py --overwrite true --overwrite-vars true --update-on-launch true

- name: prevent ubuntu deleting /tmp folder on reboot
command: echo > /etc/init/mounted-tmp.conf

- name: patch ubuntu weekly at 5 Sundays
cron:
name: "apt-get update"
minute: "0"
hour: "5"
weekday: "sun"
job: "apt-get update"

- name: upgrade ubuntu weekly at 5:15 Sundays
cron:
name: "apt-get -y upgrade"
minute: "15"
hour: "5"
weekday: "sun"
job: "apt-get -y upgrade"

- name: create /backup
file: path=/backup state=directory

- name: setup Backups for AWX docker containers
blockinfile:
path: /backup/backup_docker_AWX.sh
block: |
DATE=`date +%m-%d-%Y`
# Create Tar backups from the containers
docker save -o /backup/awx_test_backup_$DATE.tar ansible/awx_task
docker save -o /backup/awx_web_backup_$DATE.tar ansible/awx_web
docker save -o /backup/rabbitmq_backup_$DATE.tar rabbitmq
docker save -o /backup/postgres_backup_$DATE.tar postgres
docker save -o /backup/memcached_backup_$DATE.tar memcached
tar -cvf /backup/postgres_tmp_backup_$DATE.tar /tmp/pgdocker
create: yes

- name: make backup_docker_AWX.sh executable
command: chmod +x /backup/backup_docker_AWX.sh

- name: backup AWX's docker containers weekly at 5am on Mondays
cron:
name: "/backup/backup_docker_AWX.sh"
minute: "0"
hour: "5"
weekday: "mon"
job: "/backup/backup_docker_AWX.sh"

0 comments on commit 0ecf98d

Please sign in to comment.