Alan_Batie
(Alan Batie)
January 19, 2017, 1:20am
1
I’m giving ansible a try, and it seems the examples aren’t quite right - using authorized_keys as a starting point:
http://docs.ansible.com/ansible/authorized_key_module.html
cat e.yml
name: Set authorized key took from file
authorized_key:
user: charlie
state: present
key: “{{ lookup(‘file’, ‘/home/charlie/.ssh/id_rsa.pub’) }}”
ansible-playbook e.yml
ERROR! ‘authorized_key’ is not a valid attribute for a Play
The error appears to have been in ‘/etc/ansible/e.yml’: line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
name: Set authorized key took from file
^ here
I use a yaml syntax validator, which didn’t like the comment after name: but removing that doesn’t change anything.
sivel
(sivel)
January 19, 2017, 6:04pm
2
You have not created a playbook, effectively you have only created a tasks file. A playbook will have a hosts
declaration, and all tasks will be under a tasks
section.
See http://docs.ansible.com/ansible/playbooks_intro.html#playbook-language-example for more information.
Matt_Davis
(Matt Davis)
January 19, 2017, 7:54pm
3
PS: Alan Batie of Agora fame?
Alan_Batie
(Alan Batie)
January 19, 2017, 8:26pm
4
It’s still not happy with it:
ansible-playbook e.yml --list-hosts
ERROR! Syntax Error while loading YAML.
The error appears to have been in ‘/etc/ansible/e.yml’: line 5, column 1, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
authorized_key:
user: charlie
^ here
cat e.yml
hosts: all
tasks:
name: Make sure admin03 root ssh key is present
authorized_key:
user: charlie
state: present
key: “{{ lookup(‘file’, ‘/home/charlie/.ssh/id_rsa.pub’) }}”
sivel
(sivel)
January 19, 2017, 8:41pm
5
A direct copy paste from your email works without problems for me:
$ ansible-playbook e.yml --list-hosts --list-tasks
playbook: e.yml
play #1 (all): all TAGS:
pattern: [u’all’]
hosts (1):
localhost
tasks:
Make sure admin03 root ssh key is present TAGS:
I’m not sure if maybe you have tabs, or mixed indentation that didn’t translate via email? Generally speaking, make sure you only uses spaces in YAML.
Alan_Batie
(Alan Batie)
January 19, 2017, 9:17pm
6
Tabs were it, arrgh. Thanks!