using ansible as makefiles to unite your developers
TRANSCRIPT
Using Ansibleas Makefiles
to unite your developers
Ansible is mostly used for:
• Provisioning • Configuration Management • App Deployment • Continuous Delivery • Security & Compliance • Orchestration
Application
ApplicationFrontend
ApplicationBackend
Frontend
ApplicationBackend
Frontend
Operations
ApplicationBackend
Frontend
Operations
Why Ansibleinstead 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 filescopy-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.xmlsymlink-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=../buildSRC_DIR=../srcdeclare -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=../buildSRC_DIR=../srcdeclare -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 filescopy-app:
cp -R $(SRC_DIR) $(BUILD_DIR)
# Create local.xml symlinksymlink-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