Trellis: Unable to install SSMTP when hostname is not set

Created on 27 Mar 2015  路  5Comments  路  Source: roots/trellis

Hello,

I'm currently setting up deploy in an Amazon VPC, and the install ssmtp fails because the hostname FQDN is not defined.

I get this error:

failed: [54.172.107.151] => {"failed": true}
stderr: hostname: Name or service not known
dpkg: error processing package ssmtp (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 ssmtp
E: Sub-process /usr/bin/dpkg returned an error code (1)

stdout: Reading package lists...
Building dependency tree...
Reading state information...
The following NEW packages will be installed:
  ssmtp
0 upgraded, 1 newly installed, 0 to remove and 82 not upgraded.
Need to get 46.2 kB of archives.
After this operation, 8192 B of additional disk space will be used.
Get:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ trusty/universe ssmtp amd64 2.64-7 [46.2 kB]
Preconfiguring packages ...
Fetched 46.2 kB in 0s (465 kB/s)
Selecting previously unselected package ssmtp.
(Reading database ... 57425 files and directories currently installed.)
Preparing to unpack .../ssmtp_2.64-7_amd64.deb ...
Unpacking ssmtp (2.64-7) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Setting up ssmtp (2.64-7) ...

msg: 'apt-get install 'ssmtp'' failed: hostname: Name or service not known
dpkg: error processing package ssmtp (--configure):
 subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
 ssmtp
E: Sub-process /usr/bin/dpkg returned an error code (1)


FATAL: all hosts have already failed -- aborting

Due to the way AWS VPC work, the FQDN is not defined internally (to my understanding), and indeed running hostname --fqdn return hostname: Name or service not known. Digging around, I found a proposed solution in one of Chef issue.

My limited knowledge of Ansible has gotten me this solution (from the issue comments):

- name: Get the FQDN
  shell: "echo \"$(/sbin/ifconfig eth0 | grep inet\\ addr: | cut -d: -f2 | cut -d\\  -f1) $(hostname)\""
  register: fqdn
  ignore_errors: True

- name: Set FQDN correctly
  lineinfile: dest=/etc/hosts
              line="{{fqdn.stdout}}"

My questions are:

  • should that be something included in Bedrock-Ansible?
  • is there a more "Ansible way" of doing this?

I could submit a pull request if you thinks it's appropriate.

Thanks!

Most helpful comment

Ok, keeping this closed. Hostname in /etc/hosts and /etc/hostname did not match up, the DO box had been brought up and then the name changed.

All 5 comments

More errors about this reported:

https://bugs.launchpad.net/ubuntu/+source/ssmtp/+bug/582191
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=611302

Kind of hesitant to add this by default but there might be a more straightforward way. Could have a variable to define the main hostname and add that if necessary.

@louim did you end up using your method to fix this? I'm now thinking it's not a bad idea to always ensure there's a FQDN hostname.

@louim feel free to re-open this if you want.

Just received this on a DO droplet and fresh Trellis clone....

Setting up ssmtp (2.64-7) ...
hostname: Name or service not known

Ok, keeping this closed. Hostname in /etc/hosts and /etc/hostname did not match up, the DO box had been brought up and then the name changed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MasonFI picture MasonFI  路  5Comments

reverbsoul picture reverbsoul  路  8Comments

strarsis picture strarsis  路  5Comments

nathanielks picture nathanielks  路  6Comments

swalkinshaw picture swalkinshaw  路  4Comments