Using Ansible
as Makefiles
to unite your
developers
Ansible is mostly used for:
• Provisioning
• Configuration Management
• App Deployment
• Continuous Delivery
• Security & Compliance
• Orchestration

Application
Application
Frontend
Application
Backend
Frontend
Application
Backend
Frontend
Operations
Application
Backend
Frontend
Operations
Why Ansible
instead of
Makefiles?
Readability
BUILD_DIR=../build
# Clean old build(s)
clean:
rm -rf $(BUILD_DIR)
vars:
- build_dir: ../build

tasks:
- name: Clean old build(s)
file:
path: "{{ build_dir }}"
state: absent
Makefile Ansible
BUILD_DIR=../build

SRC_DIR=../src
# Copy all app files
copy-app:
cp -R $(SRC_DIR) $(BUILD_DIR)
vars:
- build_dir: ../build
- src_dir: ../src

tasks:
- name: Copy all app files
copy:
src: "{{ src_dir }}"
dest: "{{ build_dir }}"
Makefile Ansible
BUILD_DIR=../build
# Create symlink of local.xml
symlink-localxml:
ln -fs /path/to/local.xml 
$(BUILD_DIR)/local.xml
vars:
- build_dir: ../build

tasks:
- name: Create symlink of local.xml
file:
src: /path/to/local.xml
dest: "{{ build_dir }}/local.xml”
state: link
Makefile Ansible
BUILD_DIR=../build
SRC_DIR=../src
declare -A APP_DEPENDENCIES=
([“SRC”]=vendor [“DEST"]=vendor) 
([“SRC"]=node_modules/app.js [“DEST”]=js)
# Copy app dependencies (PHP & JS)
copy-dependencies:
for item in "$${!APP_DEPENDENCIES[@]}" ; do 
cp -rT --preserve=mode,timestamp,links 
”./$${item['SRC']}" 
“${BUILD_DIR}/$${item[‘DEST']}"; 
done
vars:
- build_dir: ../build
- app_dependencies:
- { src: vendor, dest: vendor }
- { src: node_modules/app.js, dest: js }

tasks:
- name: Copy app dependencies (PHP & JS)
copy:
src: "./{{ item.src }}"
dest: "{{ build_dir }}{{ item.dest }}"
follow: yes
with_items: app_dependencies
Makefile Ansible
Not sure if that works,
Makefiles are complex indeed ;D
BUILD_DIR=../build
SRC_DIR=../src
declare -A APP_DEPENDENCIES=
([“SRC"]=vendor ["DEST"]=vendor) 
(["SRC"]=node_modules/app.js ["DEST"]=js)
# Clean old build(s)
clean:
rm -rf $(BUILD_DIR)
# Copy all app files
copy-app:
cp -R $(SRC_DIR) $(BUILD_DIR)
# Create local.xml symlink
symlink-localxml:
ln -fs /path/to/local.xml 
$(BUILD_DIR)/local.xml
# Copy app dependencies (PHP & JS)
copy-dependencies:
for item in "$${!APP_DEPENDENCIES[@]}" ; do 
cp -rT --preserve=mode,timestamp,links 
”./$${item['SRC']}" 
“${BUILD_DIR}/$${item['DEST']}" ; 
done
vars:
- build_dir: ../build
- src_dir: ../src
- app_dependencies:
- { src: vendor, dest: vendor }
- { src: node_modules/app.js, dest: js }
tasks:
- name: Clean old build(s)
file:
path: "{{ build_dir }}"
state: absent
- name: Copy all app files
copy:
src: "{{ src_dir }}"
dest: "{{ build_dir }}"
- name: Create local.xml symlink
file:
src: /path/to/local.xml
dest: "{{ build_dir }}/local.xml”
state: link
- name: Copy app dependencies (PHP & JS)
copy:
src: "./{{ item.src }}"
dest: "{{ build_dir }}{{ item.dest }}"
follow: yes
with_items: app_dependencies
Makefile Ansible
Questions ?
Thank you ;D
@thiagoalessio
github.com/thiagoalessio

Using Ansible as Makefiles to unite your developers

  • 1.
    Using Ansible as Makefiles tounite your developers
  • 2.
    Ansible is mostlyused for: • Provisioning • Configuration Management • App Deployment • Continuous Delivery • Security & Compliance • Orchestration

  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 11.
  • 12.
  • 13.
    BUILD_DIR=../build # Clean oldbuild(s) clean: rm -rf $(BUILD_DIR) vars: - build_dir: ../build
 tasks: - name: Clean old build(s) file: path: "{{ build_dir }}" state: absent Makefile Ansible
  • 14.
    BUILD_DIR=../build
 SRC_DIR=../src # Copy allapp files copy-app: cp -R $(SRC_DIR) $(BUILD_DIR) vars: - build_dir: ../build - src_dir: ../src
 tasks: - name: Copy all app files copy: src: "{{ src_dir }}" dest: "{{ build_dir }}" Makefile Ansible
  • 15.
    BUILD_DIR=../build # Create symlinkof local.xml symlink-localxml: ln -fs /path/to/local.xml $(BUILD_DIR)/local.xml vars: - build_dir: ../build
 tasks: - name: Create symlink of local.xml file: src: /path/to/local.xml dest: "{{ build_dir }}/local.xml” state: link Makefile Ansible
  • 16.
    BUILD_DIR=../build SRC_DIR=../src declare -A APP_DEPENDENCIES= ([“SRC”]=vendor[“DEST"]=vendor) ([“SRC"]=node_modules/app.js [“DEST”]=js) # Copy app dependencies (PHP & JS) copy-dependencies: for item in "$${!APP_DEPENDENCIES[@]}" ; do cp -rT --preserve=mode,timestamp,links ”./$${item['SRC']}" “${BUILD_DIR}/$${item[‘DEST']}"; done vars: - build_dir: ../build - app_dependencies: - { src: vendor, dest: vendor } - { src: node_modules/app.js, dest: js }
 tasks: - name: Copy app dependencies (PHP & JS) copy: src: "./{{ item.src }}" dest: "{{ build_dir }}{{ item.dest }}" follow: yes with_items: app_dependencies Makefile Ansible Not sure if that works, Makefiles are complex indeed ;D
  • 17.
    BUILD_DIR=../build SRC_DIR=../src declare -A APP_DEPENDENCIES= ([“SRC"]=vendor["DEST"]=vendor) (["SRC"]=node_modules/app.js ["DEST"]=js) # Clean old build(s) clean: rm -rf $(BUILD_DIR) # Copy all app files copy-app: cp -R $(SRC_DIR) $(BUILD_DIR) # Create local.xml symlink symlink-localxml: ln -fs /path/to/local.xml $(BUILD_DIR)/local.xml # Copy app dependencies (PHP & JS) copy-dependencies: for item in "$${!APP_DEPENDENCIES[@]}" ; do cp -rT --preserve=mode,timestamp,links ”./$${item['SRC']}" “${BUILD_DIR}/$${item['DEST']}" ; done vars: - build_dir: ../build - src_dir: ../src - app_dependencies: - { src: vendor, dest: vendor } - { src: node_modules/app.js, dest: js } tasks: - name: Clean old build(s) file: path: "{{ build_dir }}" state: absent - name: Copy all app files copy: src: "{{ src_dir }}" dest: "{{ build_dir }}" - name: Create local.xml symlink file: src: /path/to/local.xml dest: "{{ build_dir }}/local.xml” state: link - name: Copy app dependencies (PHP & JS) copy: src: "./{{ item.src }}" dest: "{{ build_dir }}{{ item.dest }}" follow: yes with_items: app_dependencies Makefile Ansible
  • 18.
  • 19.