Skip to content

Instantly share code, notes, and snippets.

@ScottSturdivant
Created June 13, 2013 17:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ScottSturdivant/5775443 to your computer and use it in GitHub Desktop.
Save ScottSturdivant/5775443 to your computer and use it in GitHub Desktop.
setting hostname via ansible
- name: Set the hostname in rc.conf
lineinfile: dest=/etc/rc.conf regexp="^hostname" line='hostname="{{ hostname }}"'
register: hostname
- name: Set the hostname
shell: hostname {{ hostname }}
when: hostname.changed
TASK: [Set the hostname in rc.conf] *******************************************
changed: [admin] => {"changed": true, "item": "", "msg": "line replaced"}
TASK: [Set the hostname] ******************************************************
failed: [admin] => {"changed": true, "cmd": "hostname {u'msg': u'line replaced', 'item': '', u'changed': True, 'invocation': {'module_name': 'lineinfile', 'module_args': u'dest=/etc/rc.conf regexp=\"^hostname\" line=\\'hostname=\"foobar.network.local\"\\''}} ", "delta": "0:00:00.001940", "end": "2013-06-13 10:02:25.053085", "item": "", "rc": 2, "start": "2013-06-13 10:02:25.051145"}
stderr: Syntax error: Unterminated quoted string
FATAL: all hosts have already failed -- aborting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment