can't start service on systemd with ampersand (openvpn@server)

I’m trying to control openvpn on an arch linux server.

I am able to successfully start the service on the box with

systemctl start openvpn@server

but when I try to do some from ansible I get:

failed: [laprouter] => {“failed”: true, “item”: “”}
msg: Failed to issue method call: Unit name openvpn@.service is not valid.

FATAL: all hosts have already failed – aborting

Here is the part of the yml config:

  • name: Ensure openvpn service enabled
    service:
    name=“openvpn@server”
    state=started

Is this an error in my configuration?

You shouldn’t have to provide the “at” symbol here.

The @ symbol is required by systemd for dynamic daemons that load a specific configuration file. For openvpn, you can have multiple .conf files for multiple openvpn daemons. The @ is required for openvpn to work on a systemd system.

e.g. on my client I have
systemctl start openvpn@workbench

where workbench is the name of the conf file: /etc/openvpn/workbench.conf

Hmm.

Please make sure there is a github ticket filed. Or if you would like to work on this, that’s fine too :slight_smile:

Will do. I have been looking for an excuse to improve my python and figure out how ansible modules are written.

I’ll file a ticket too since I’m sure someone else will be able to patch it much more quickly than I.

Hi guys

I’m running from source and still getting this problem - is anyone else able to use @ signs in services?

task:

  • name: enable and start eth0 service
    service: name=netctl@eth0.service state=started enabled=yes

error:

TASK: [network | enable and start eth0 service] *******************************
<192.168.1.253> ESTABLISH CONNECTION FOR USER: root
<192.168.1.253> REMOTE_MODULE service name=netctl@eth0.service state=started enabled=yes
<192.168.1.253> EXEC [‘sshpass’, ‘-d10’, ‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/home/alex/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘Port=22’, ‘-o’, ‘GSSAPIAuthentication=no’, ‘-o’, ‘PubkeyAuthentication=no’, ‘-o’, ‘User=root’, ‘-o’, ‘ConnectTimeout=10’, ‘192.168.1.253’, “/bin/sh -c ‘mkdir -p $HOME/.ansible/tmp/ansible-tmp-1391803906.5-98641080919224 && echo $HOME/.ansible/tmp/ansible-tmp-1391803906.5-98641080919224’”]
<192.168.1.253> PUT /tmp/tmpxsF3YP TO /root/.ansible/tmp/ansible-tmp-1391803906.5-98641080919224/service
<192.168.1.253> EXEC [‘sshpass’, ‘-d10’, ‘ssh’, ‘-C’, ‘-tt’, ‘-vvv’, ‘-o’, ‘ControlMaster=auto’, ‘-o’, ‘ControlPersist=60s’, ‘-o’, ‘ControlPath=/home/alex/.ansible/cp/ansible-ssh-%h-%p-%r’, ‘-o’, ‘Port=22’, ‘-o’, ‘GSSAPIAuthentication=no’, ‘-o’, ‘PubkeyAuthentication=no’, ‘-o’, ‘User=root’, ‘-o’, ‘ConnectTimeout=10’, ‘192.168.1.253’, “/bin/sh -c ‘/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1391803906.5-98641080919224/service; rm -rf /root/.ansible/tmp/ansible-tmp-1391803906.5-98641080919224/ >/dev/null 2>&1’”]
failed: [192.168.1.253] => {“failed”: true, “item”: “”}
msg: Failed to issue method call: Unit name netctl@.service is not valid.

FATAL: all hosts have already failed – aborting

ansible version:

ansible 1.5 (devel 2d88246c9d) last updated 2014/02/07 20:06:49 (GMT +100)

I haven’t had enough time to actually fix this. If someone else can do it more quickly, that would be awesome. In the meantime, will have to use the command module.