Skip to content

Commit

Permalink
Merge pull request #1 from TamiTakamiya/suggestions-8058f71
Browse files Browse the repository at this point in the history
Ansible code bot recommendations
  • Loading branch information
TamiTakamiya committed Mar 4, 2024
2 parents 8058f71 + c3e8ace commit 8277f36
Show file tree
Hide file tree
Showing 67 changed files with 271 additions and 272 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ name: colors
version: 1.0.0
readme: README.md
authors:
- your name <example@domain.com>
- your name <example@domain.com>
4 changes: 2 additions & 2 deletions collection/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
my_color_choice: blue

tasks:
- name: "Verify {{ my_color_choice }} is a form of blue."
- name: Verify {{ my_color_choice }} is a form of blue.
assert:
that: my_color_choice is local.colors.blue

- name: "Verify yellow is not a form of blue."
- name: Verify yellow is not a form of blue.
assert:
that: "'yellow' is not local.colors.blue"
8 changes: 4 additions & 4 deletions deployments-balancer/playbooks/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
---
- hosts: app
become: yes
become: true
serial: 1

pre_tasks:
- name: Disable the backend server in HAProxy.
haproxy:
state: disabled
host: '{{ inventory_hostname }}'
host: "{{ inventory_hostname }}"
socket: /var/lib/haproxy/stats
backend: habackend
delegate_to: "{{ item }}"
Expand All @@ -21,15 +21,15 @@
post_tasks:
- name: Wait for backend to come back up.
wait_for:
host: '{{ inventory_hostname }}'
host: "{{ inventory_hostname }}"
port: 80
state: started
timeout: 60

- name: Enable the backend server in HAProxy.
haproxy:
state: enabled
host: '{{ inventory_hostname }}'
host: "{{ inventory_hostname }}"
socket: /var/lib/haproxy/stats
backend: habackend
delegate_to: "{{ item }}"
Expand Down
6 changes: 3 additions & 3 deletions deployments-balancer/playbooks/provision.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- name: Firewall configuration.
hosts: all
become: yes
become: true

vars:
firewall_allowed_tcp_ports:
Expand All @@ -17,7 +17,7 @@

- name: HAProxy Load Balancer setup.
hosts: balancer
become: yes
become: true

vars:
haproxy_backend_servers:
Expand All @@ -31,7 +31,7 @@

- name: Apache webserver setup.
hosts: app
become: yes
become: true

roles:
- geerlingguy.apache
20 changes: 10 additions & 10 deletions deployments-rolling/playbooks/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
- hosts: nodejs-api
gather_facts: no
become: yes
gather_facts: false
become: true

vars_files:
- vars.yml
Expand All @@ -17,15 +17,15 @@
notify: restart forever apps

- name: Stop all running instances of the app.
command: "forever stopall"
command: forever stopall
when: app_updated.changed

- name: Ensure Node.js API app dependencies are present.
npm: "path={{ app_directory }}"
npm: path={{ app_directory }}
when: app_updated.changed

- name: Run Node.js API app tests.
command: "npm test chdir={{ app_directory }}"
command: npm test chdir={{ app_directory }}
when: app_updated.changed

- name: Get list of all running Node.js apps.
Expand All @@ -34,15 +34,15 @@
changed_when: false

- name: Ensure Node.js API app is started.
command: "forever start {{ app_directory }}/app.js"
when: "forever_list.stdout.find('app.js') == -1"
command: forever start {{ app_directory }}/app.js
when: forever_list.stdout.find('app.js') == -1

- name: Add cron entry to start Node.js API app on reboot.
cron:
name: "Start Node.js API app"
name: Start Node.js API app
special_time: reboot
job: "forever start {{ app_directory }}/app.js"
job: forever start {{ app_directory }}/app.js

handlers:
- name: restart forever apps
command: "forever restartall"
command: forever restartall
4 changes: 2 additions & 2 deletions deployments-rolling/playbooks/provision.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
- hosts: nodejs-api
become: yes
become: true

vars:
nodejs_install_npm_user: root
npm_config_prefix: "/usr"
npm_config_prefix: /usr
nodejs_npm_global_packages:
- forever
firewall_allowed_tcp_ports:
Expand Down
2 changes: 1 addition & 1 deletion deployments-rolling/playbooks/vars.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---
app_repository: https://github.com/geerlingguy/demo-nodejs-api.git
app_version: "2.0.0"
app_version: 2.0.0
app_directory: /opt/demo-nodejs-api
12 changes: 6 additions & 6 deletions deployments/playbooks/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- hosts: all
become: yes
become: true

vars_files:
- vars.yml
Expand All @@ -27,20 +27,20 @@
dest: "{{ app_directory }}/config/secrets.yml"
owner: "{{ app_user }}"
group: "{{ app_user }}"
mode: 0664
mode: "0664"
notify: restart nginx

- name: Install required dependencies with bundler.
command: "bundle install --path vendor/bundle chdir={{ app_directory }}"
command: bundle install --path vendor/bundle chdir={{ app_directory }}
when: app_updated.changed == true
notify: restart nginx

- name: Check if database exists.
stat: "path={{ app_directory }}/db/{{ app_environment.RAILS_ENV }}.sqlite3"
stat: path={{ app_directory }}/db/{{ app_environment.RAILS_ENV }}.sqlite3
register: app_db_exists

- name: Create database.
command: "bundle exec rake db:create chdir={{ app_directory }}"
command: bundle exec rake db:create chdir={{ app_directory }}
when: app_db_exists.stat.exists == false
notify: restart nginx

Expand All @@ -59,5 +59,5 @@
state: directory
owner: "{{ app_user }}"
group: "{{ app_user }}"
recurse: yes
recurse: true
notify: restart nginx
4 changes: 2 additions & 2 deletions deployments/playbooks/provision.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- hosts: all
become: yes
become: true

vars_files:
- vars.yml
Expand All @@ -26,4 +26,4 @@
state: directory
owner: "{{ app_user }}"
group: "{{ app_user }}"
mode: 0755
mode: "0755"
2 changes: 1 addition & 1 deletion deployments/playbooks/vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ app_environment:
RAILS_ENV: production

# Variables for Passenger and Nginx.
passenger_server_name: 0.0.0.0
passenger_server_name: "0.0.0.0"
passenger_app_root: /opt/demo-rails-app/public
passenger_app_env: production
passenger_ruby: /usr/local/bin/ruby
Expand Down
4 changes: 2 additions & 2 deletions docker-flask/provisioning/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
name: www
state: started
command: python3 /opt/www/index.py
ports: "80:80"
ports: 80:80

- name: Run a MySQL container.
docker_container:
image: db:latest
name: db
state: started
volumes_from: data
ports: "3306:3306"
ports: 3306:3306
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: flask
Expand Down
6 changes: 3 additions & 3 deletions docker-flask/provisioning/www/playbook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

tasks:
- name: Get host IP address.
shell: "/sbin/ip route | awk '/default/ { print $3 }'"
shell: /sbin/ip route | awk '/default/ { print $3 }'
register: host_ip
changed_when: false

Expand All @@ -16,10 +16,10 @@
template:
src: /etc/ansible/index.py.j2
dest: /opt/www/index.py
mode: 0755
mode: "0755"

- name: Copy Flask templates into place.
copy:
src: /etc/ansible/templates
dest: /opt/www
mode: 0755
mode: "0755"
14 changes: 7 additions & 7 deletions docker-hubot/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@
pre_tasks:
- name: Make the latest version of the base image available locally.
docker_image:
name: '{{ base_image }}'
name: "{{ base_image }}"
source: pull
force_source: true

- name: Create the Docker container.
docker_container:
image: '{{ base_image }}'
name: '{{ container_name }}'
image: "{{ base_image }}"
name: "{{ container_name }}"
command: sleep infinity

- name: Add the newly created container to the inventory.
add_host:
hostname: '{{ container_name }}'
hostname: "{{ container_name }}"
ansible_connection: docker

roles:
- name: hubot-slack
delegate_to: '{{ container_name }}'
delegate_to: "{{ container_name }}"

post_tasks:
- name: Clean up the container.
shell: >
apt-get remove --purge -y python &&
rm -rf /var/lib/apt/lists/*
delegate_to: '{{ container_name }}'
delegate_to: "{{ container_name }}"

- name: Commit the container.
command: >
Expand All @@ -49,5 +49,5 @@
- name: Remove the container.
docker_container:
name: '{{ container_name }}'
name: "{{ container_name }}"
state: absent
15 changes: 8 additions & 7 deletions docker-hubot/roles/hubot-slack/meta/main.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
galaxy_info:
author: your name
description: your description
Expand Down Expand Up @@ -45,13 +46,13 @@ galaxy_info:
# - 99.99

galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.

dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.
# if you add dependencies to this list.
12 changes: 6 additions & 6 deletions docker-hubot/roles/hubot-slack/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
npm:
name: "{{ item }}"
state: present
global: yes
global: true
with_items:
- yo
- generator-hubot

- name: Ensure hubot user exists.
user:
name: hubot
create_home: yes
create_home: true
home: "{{ hubot_home }}"

- name: Generate hubot.
Expand All @@ -28,7 +28,7 @@
--adapter=slack
--defaults
chdir={{ hubot_home }}
become: yes
become: true
become_user: hubot

- name: Remove certain scripts from external-scripts.json.
Expand All @@ -37,9 +37,9 @@
regexp: "{{ item }}"
state: absent
with_items:
- 'redis-brain'
- 'heroku'
become: yes
- redis-brain
- heroku
become: true
become_user: hubot

- name: Remove the hubot-scripts.json file.
Expand Down
Loading

0 comments on commit 8277f36

Please sign in to comment.