Automate Discourse Docker with Ansible

Hello folks,

we would like to announce a stable version of Ansible Discourse, it is an ansible playbook that helps you to confgure and provision the Discourse Docker easily.

I hope that this project can be useful for everyone who wants to install and configure a new Discourse.

Do you have any feedback?

Contributors are welcome :hugs:

At the moment we wrote two scripts (scripts/) that can be used to run the provisioning on a local vagrant machine or AWS. It could be useful to add support for other providers, like DigitalOcean, Google Cloud, and other.

8 Likes

I would like to experiment with it on GANDI.net is tha’s not too much trouble.

Thanks

1 Like

This is exactly what I’m looking for.

I’ve been using Ansible a lot thanks to the fantastic Roots Trellis for WordPress, and I’ve come to realise the benefits of using automated provisions and deploys with the ability to store the configs in git.

I look after several discourse instances and this approach will allow me to properly standardise everything.

I’m going to have a play with this and report back.

Thanks!

1 Like

I’m also going to see if I can get this working with LXD.

This is great! But why is it exclusive to AWS? What if I would like to use Discourse Docker and Ansible to provision this on another VPS such as Linode, Vultr or DigitalOcean?

Any chance to make this a little more flexible? Is there a hard requirement on AWS? I see that AWS-CLI is listed as a requirement

Hi @vesper8, take a look at the Provisioning section. As you will see there, you can easily run the provision against a local host (like vagrant), and of course, it will be very easy to adapt the script to make it works against other environments, like DigitalOcean or other.

2 Likes

Have you been able to skip the registration/after installation wizard. I am trying to make an ansible role to install discourse and skip any GUI configuration such as register or import custom theme. it been days looking for a way

The registration wizard will not be shown if there is an existing admin user. So just create such a user and you’re good.

4 Likes

Thank you, it worked for me using rake admin:create,

Now, I am trying to add this part under RUN: in the app.yml

 - exec:rails r "u = User.create!(username: '{{ discourse_developer_username }}', email: '{{ discourse_developer_emails }}', password: ' {{ discourse_developer_password }}', admin: true)"

but it fails, even when I uncomment:

- exec: rails r "SiteSetting.notification_email='discourse@example.com'"

so how to run a rails command with out going through:

cd /var/discourse 
./launcher enter app
rails r "......." which  it works 

and one more question, how to import theme through command line.

One solution would be to restore a backup with the user and theme you want.

when I added

exec: cd /var/www/discourse && rails r "SiteSetting.notification_email= 'discourse@test.kfupm.edu.sa'"

worked!!!

the issue was when I bootstrap the container it return an exception because of ‘:’ used in the command,
to solve this I put the command in a file.rb and in the custom command section I added

exec: cd /var/www/discourse && rails r file.rb

of course you need to copy the file.rb into the container.

1 Like

Hi @ahmed_alamiry I have added the same command in app.yml custom command section but I am getting the below error. If you don’t mind could you please guide me.

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && rails r file.rb failed with return #<Process::Status: pid 5317 exit 1>
Location of failure: /pups/lib/pups/exec_command.rb:112:in `spawn'
exec failed with the params "cd /var/www/discourse && rails r file.rb"

Note : I have tried with placed the file under "/var/discourse/container# " then place inside the container “/var/www/discourse/” but both the time I got the same error.

Please guide me to configure this, Many thanks in advance.

@Muthukkumar what inside file.rb ?
Place the file.rb in /var/discourse/shared/standalone (or what ever path in the volume section).
In app.yml under run add:

  • exec: cp /shared/file.rb /var/www/discourse
  • exec: cd /var/www/discourse && rails r file.rb
1 Like

Hi @ahmed_alamiry, Thanks a lot for the quick response, below is the details.

file.rb
rails r “u = User.create!(username: ‘{{ Muthukkumar }}’, email: ‘{{ muthukkumar@abc.net }}’, password: ’ {{ password123 }}’, admin: true)”

for me this changes are working again I am getting the discourse wizard setup.

the account created but not activated.
you missing "u.activate "

1 Like

So my file.rb should be like this ?

rails r “u = User.create!(username: ‘{{ Muthukkumar }}’, email: ‘{{ muthukkumar@abc.net }}’, password: ’ {{ mypin }}’, admin: true)”
rails r “u.activate”

no, file.rb content:
u = User.create!(username: ‘{{ Muthukkumar }}’, email: ‘{{ [ muthukkumar@abc.net] }}’, password: ’ {{ password }}’, admin: true)”; u.activate

Then:
rails r file.rb

Notice the “;”

1 Like

@ahmed_alamiry yes got it let me try this.

This redirects to a Cloudformation Discord now, with no mention of Ansible or a playbook. Is your Ansible Discord playbook discontinued now? Can you tell more about why if this is the case?

Do be aware this is an #unsupported-install configuration so if anyone does proceed to use discourse-docker with Ansible, it will not be supported here.

3 Likes