Skip to content

Instantly share code, notes, and snippets.

@jruels
Created December 14, 2013 21:54
Show Gist options
  • Save jruels/7965424 to your computer and use it in GitHub Desktop.
Save jruels/7965424 to your computer and use it in GitHub Desktop.
Playbook with everything.
---
- name: update cache
apt: update_cache=yes
- name: install vim
apt: pkg=vim-nox state=installed
$ tree
.
├── LICENSE
├── README.md
├── Vagrantfile
├── Vagrantfile.works
├── group_vars
│   └── all
├── hosts
├── roles
│   ├── common
│   │   ├── files
│   │   │   └── iptables-save
│   │   ├── handlers
│   │   │   └── main.yml
│   │   └── tasks
│   │   └── main.yml
│   ├── magento
│   │   └── tasks
│   │   └── main.yml
│   ├── mysql
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── templates
│   │   └── my.cnf.j2
│   ├── nginx
│   │   ├── handlers
│   │   │   └── main.yml
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── templates
│   │   └── default.conf
│   └── php-fpm
│   ├── handlers
│   │   └── main.yml
│   ├── tasks
│   │   └── main.yml
│   └── templates
│   ├── magento.conf
│   └── mcrypt.ini
├── site.yml
$ cat group_vars/all
---
# Which version of Magento to deploy
mag_version: 1.7.0.2
# These are the Magento database settings
mag_db_name: magento
mag_db_user: magento
mag_db_password: Sento9767$
# You shouldn't need to change this.
mysql_port: 3306
# This is used for the nginx server configuration, but # access to the
# Magento site is not restricted by a # named host.
server_hostname: localhost
---
- name: Download Magento Downloader
get_url: url=http://www.magentocommerce.com/downloads/assets/{{ mag_version }}/magento-{{ mag_version }}.tar.gz dest=/srv/magento-{{ mag_version }}.tar.gz
- name: Extract Archive
command: chdir=/srv/ /bin/tar xvf magento-{{ mag_version }}.tar.gz creates=/srv/magento
- name: Change ownership of Magento installation
file: path=/srv/magento/ owner=www-data group=www-data state=directory recurse=yes
---
- name: Install Mysql package
apt: name={{ item }} state=present
with_items:
- mysql-server
- python-mysqldb
- name: Create Mysql configuration file
template: src=my.cnf.j2 dest=/etc/my.cnf
notify:
- restart mysql
- name: Start Mysql Service
service: name=mysql state=started enabled=true
- name: Create Magento database
mysql_db: name={{ mag_db_name }} state=present
- name: Create Magento database user
mysql_user: name={{ mag_db_user }} password={{ mag_db_password }} priv={{ mag_db_name }}.*:ALL host='localhost' state=present
- debug: msg="this is ansibleweb1_ip value {{ hostvars[ansibleweb1]['ansible_' + iface].ipv4.address }}
---
- name: Install nginx
apt: name=nginx state=present
- name: Copy nginx configuration for Magento
template: src=default.conf dest=/etc/nginx/conf.d/default.conf
notify: restart nginx
- name: Move default nginx configuration file
command: mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old creates=/etc/nginx/sites-available/default.old
notify: restart nginx
---
- name: Install php-fpm and deps
apt: name={{ item }} state=present
with_items:
- php5
- php5-fpm
- php5-enchant
- php5-idn
- php5-mysqlnd
- libphp-phpmailer
- libphp-simplepie
- php5-xmlrpc
- php5-mcrypt
- php5-gd
- php5-cli
- name: Disable default pool
command: mv /etc/php5/fpm/pool.d/www.conf /etc/php5/fpm/pool.d/www.disabled creates=/etc/php5/fpm/pool.d/www.disabled
- name: Copy php-fpm configuration
template: src=magento.conf dest=/etc/php5/fpm/pool.d/
- name: Copy mcrypt.ini to correct location
template: src=mcrypt.ini dest=/etc/php5/mods-available/
- name: Fix php-fpm for Ubuntu 13.10
command: php5enmod mcrypt
notify: restart php-fpm
cat site.yml
---
- name: Install Magento, Nginx, and PHP-FPM on web servers
hosts: web
user: root
# sudo: yes
roles:
- common
- nginx
- php-fpm
- magento
- name: Install MySQL on DB servers
hosts: db
user: root
roles:
- mysql
@tgerla
Copy link

tgerla commented Dec 14, 2013

As long as you're running the whole site playbook, and it's hitting the webserver first, the webserver's facts should be available in the "hosts: db" play. The only thing I see wrong is that this:

  • debug: msg="this is ansibleweb1_ip value {{ hostvars[ansibleweb1]['ansible_' + iface].ipv4.address }}

Should be:

  • debug: msg="this is ansibleweb1_ip value {{ hostvars['ansibleweb1']['ansible_' + iface].ipv4.address }}"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment