Skip to content

Commit

Permalink
Only use apt when binary exists, add CentOS to platform matrix (#18)
Browse files Browse the repository at this point in the history
* Only use apt for debian and ubuntu distros
* Add CentOS to the platform list

Co-authored-by: Mark Hlawatschek <[email protected]>
  • Loading branch information
dirkaholic and hlawatschek authored Jun 12, 2020
1 parent 4aa4a39 commit 906623f
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 5 deletions.
3 changes: 3 additions & 0 deletions molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ platforms:
- name: Ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
- name: CentOS7
image: centos:7
dockerfile: ../resources/Dockerfile.j2
provisioner:
name: ansible
lint:
Expand Down
3 changes: 3 additions & 0 deletions molecule/default_fingerprints/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ platforms:
- name: Ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
- name: CentOS7
image: centos:7
dockerfile: ../resources/Dockerfile.j2
provisioner:
name: ansible
lint:
Expand Down
3 changes: 3 additions & 0 deletions molecule/ignore_provisioned_flag/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ platforms:
- name: Ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
- name: CentOS7
image: centos:7
dockerfile: ../resources/Dockerfile.j2
provisioner:
name: ansible
lint:
Expand Down
3 changes: 3 additions & 0 deletions molecule/no_user_confirmation/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ platforms:
- name: Ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
- name: CentOS7
image: centos:7
dockerfile: ../resources/Dockerfile.j2
provisioner:
name: ansible
lint:
Expand Down
3 changes: 3 additions & 0 deletions molecule/noraid/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ platforms:
- name: Ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
- name: CentOS7
image: centos:7
dockerfile: ../resources/Dockerfile.j2
provisioner:
name: ansible
lint:
Expand Down
3 changes: 3 additions & 0 deletions molecule/outdated_image/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ platforms:
- name: Ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
- name: CentOS7
image: centos:7
dockerfile: ../resources/Dockerfile.j2
provisioner:
name: ansible
lint:
Expand Down
3 changes: 3 additions & 0 deletions molecule/provisioned_flag/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ platforms:
- name: Ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
- name: CentOS7
image: centos:7
dockerfile: ../resources/Dockerfile.j2
provisioner:
name: ansible
lint:
Expand Down
3 changes: 3 additions & 0 deletions molecule/raid1/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ platforms:
- name: Ubuntu18
image: ubuntu:18.04
dockerfile: ../resources/Dockerfile.j2
- name: CentOS7
image: centos:7
dockerfile: ../resources/Dockerfile.j2
provisioner:
name: ansible
lint:
Expand Down
25 changes: 20 additions & 5 deletions molecule/resources/tasks/prepare-default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,26 @@
raw: docker network connect molecule {{ inventory_hostname }}
delegate_to: localhost
- name: Update apt repositories using raw module as python might not be installed yet
raw: apt-get update
- name: Install SSH server on testinfra hosts as SSH is checked after reboot was requested
raw: apt-get install openssh-server -y
- name: Start SSH server on testinfra hosts as SSH is checked after reboot was requested
raw: service ssh start
raw: if [ $(command -v apt-get) ]; then apt-get update; fi
- name: Install SSH server on apt based hosts as SSH is checked after reboot was requested
raw: if [ $(command -v apt-get) ]; then apt-get install openssh-server -y; fi
- name: Update yum repositories using raw module as python might not be installed yet
raw: if [ $(command -v yum) ]; then yum makecache; fi
- name: Install SSH server on yum based hosts as SSH is checked after reboot was requested
raw: if [ $(command -v yum) ]; then yum -y install initscripts openssh-server && yum clean all; fi
- name: Remove default systemctl on yum based systems
raw: if [ $(command -v yum) ]; then rm -rf /bin/systemctl; rm -rf /usr/bin/systemctl; fi
- name: Prepare/overwrite docker systemctl replacement script for apt based systems
get_url:
url: https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py
dest: /usr/bin/systemctl
mode: '0775'
- name: Generate host keys on yum based hosts for SSH to work
raw: if [ $(command -v yum) ]; then /usr/bin/ssh-keygen -A; fi
- name: Start SSH server on apt based hosts as SSH is checked after reboot was requested
raw: if [ $(command -v apt-get) ]; then service ssh start; fi
- name: Start SSH server on yum based hosts as SSH is checked after reboot was requested
raw: if [ $(command -v yum) ]; then service sshd start; fi
- name: Get users homedir
raw: command echo ~
register: homedir
Expand Down
8 changes: 8 additions & 0 deletions tasks/installimage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@
timeout: 180
delegate_to: localhost

- name: Check is apt-get installed
shell: command -v apt-get >/dev/null 2>&1
changed_when: false
register: apt_get_exists
ignore_errors: yes

# uses raw instead of module as python might not be installed yet
- name: update apt repositories
raw: apt-get update
Expand All @@ -70,11 +76,13 @@
delay: 5
register: update_apt
until: update_apt.rc == 0
when: apt_get_exists.rc == 0

# uses raw instead of module as python might not be installed yet
- name: install python on remote host
raw: apt-get install python -y
changed_when: true
when: apt_get_exists.rc == 0

- name: Lookup content of installimage config file
set_fact:
Expand Down

0 comments on commit 906623f

Please sign in to comment.