Skip to content

Instantly share code, notes, and snippets.

@umidjons
Last active July 27, 2017 07:23
Show Gist options
  • Save umidjons/4d735e5301fff5dfd6df25c8ca8a4346 to your computer and use it in GitHub Desktop.
Save umidjons/4d735e5301fff5dfd6df25c8ca8a4346 to your computer and use it in GitHub Desktop.
Docker container to test moodle existance with ansible
FROM ubuntu:14.04
SHELL ["/bin/bash", "-c"]
# Installing openssh-server, apache, php and moodle
RUN set -x \
&& apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -q -y --fix-missing apache2 php5 wget openssh-server \
&& cd /tmp \
&& wget --continue --tries=100 --waitretry=1 --timeout=10 -O moodle-latest-32.tgz https://download.moodle.org/stable32/moodle-latest-32.tgz \
&& tar -xzf moodle-latest-32.tgz \
&& rm -f moodle-latest-32.tgz \
&& mv moodle /var/www/ \
&& a2dissite 000-default \
&& echo '<VirtualHost _default_:80>\n\
DocumentRoot "/var/www/moodle"\n\
<Directory "/var/www/moodle">\n\
Options Indexes FollowSymLinks\n\
AllowOverride All\n\
Require all granted\n\
</Directory>\n\
</VirtualHost>\n' >> /etc/apache2/sites-available/moodle.conf \
&& a2ensite moodle \
&& echo "root:root@123" | chpasswd \
&& sed -ri -e 's|(^PermitRootLogin )(.*)|\1yes|g' /etc/ssh/sshd_config \
&& mkdir -p /var/run/sshd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
[ec2instances]
# replace 172.17.0.2 with your container's IP
test_moodle ansible_ssh_host=172.17.0.2 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=root@123
@umidjons
Copy link
Author

Build container with:

docker build -t test_moodle .

Then run it:

docker run -d --name moodle test_moodle

Check ssh with:

Then run the discovery task using above hosts file:

ansible-playbook -v -i hosts ec2discovery.yml

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