syntax error... where there is no syntax error...

110 views
Skip to first unread message

Joost Ringoot

unread,
Mar 14, 2017, 11:35:47 AM3/14/17
to Ansible Project
But Hello,

I have this playbook,... that used to work in a previous version of ansible, I swear it did:

cat ansible/playbooks/apt/sssdconfig.yml  
---
- hosts: "{{hosts}}"
#  accelerate: true
  remote_user
: root
  tasks
:
 
- name: install auth-client-config
    apt
: name=auth-client-config state=installed
 
- name: install sssd client
    apt
: name=sssd state=installed
 
- name: install ldap pam module
    apt
: name=libpam-ldap state=installed
 
- name: configure authentication  
    command
: /usr/sbin/auth-client-config --enablesssd --enablesssdauth --enablelocauthorize --enablepamaccess --enablemkhomedir --update
 
- name: make sure the config directory is present ( workaround for a bug in sssd package)
    command
: /bin/mkdir -p /etc/sssd
 
- name: use a template sssd.conf
    copy
: src=/home/florence/ansible/files/sssd.conf dest=/etc/sssd
 
- name: ensure correct acl for the sssd directory
    file
: path=/etc/sssd mode=0600
 
- name: ensure correct acl for the sssd.conf file
    file
: path=/etc/sssd/sssd.conf mode=0600
 
- name: restart sssd
    service
: name=sssd enabled=yes state=restarted

But now this happens:

 ansible-playbook  /home/florence/ansible/playbooks/apt/sssdconfig.yml -e cal-30
ERROR! the field 'hosts' has an invalid value, which appears to include a variable that is undefined. The error was: 'hosts' is undefined

The error appears to have been in '/home/florence/ansible/playbooks/apt/sssdconfig.yml': line 2, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

---
- hosts: "{{hosts}}"
  ^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes.  Always quote template expression brackets when they
start a value. For instance:

    with_items:
      - {{ foo }}

Should be written as:

    with_items:
      - "{{ foo }}"


This is the version of ansible I use

ansible-playbook  --version
ansible-playbook 2.2.1.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/usr/share/ansible,/opt/ansible/lib']

This is the version of the server:

cat /etc/*release
NAME="Red Hat Enterprise Linux Server"
VERSION="7.2 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="7.2"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.2 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.2:GA:server"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
REDHAT_BUGZILLA_PRODUCT_VERSION=7.2
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="7.2"
Red Hat Enterprise Linux Server release 7.2 (Maipo)
Red Hat Enterprise Linux Server release 7.2 (Maipo)


Thanks,

Joost

Andrew Latham

unread,
Mar 14, 2017, 11:40:34 AM3/14/17
to ansible...@googlegroups.com
Joost

Try:

python -c 'import yaml,sys;yaml.safe_load(sys.stdin)' < ansible/playbooks/apt/sssdconfig.yml

Valid Yaml is not hard but you can add a post commit hook like the above to validate the yaml for you.

> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/4c74d755-dedb-434e-a22e-90a645bc2ab1%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.




--
- Andrew "lathama" Latham -

Kai Stian Olstad

unread,
Mar 14, 2017, 1:15:01 PM3/14/17
to ansible...@googlegroups.com
On 14. mars 2017 16:35, Joost Ringoot wrote:
> I have this playbook,... that used to work in a previous version of
> ansible, I swear it did:
>
> cat ansible/playbooks/apt/sssdconfig.yml
> ---
> - hosts: "{{hosts}}"

I wouldn't use a variable named the same as a directive.
The variable hosts is not set, and your -e should be key=value.
Are you trying to write -e hosts=cal-30 ?

--
Kai Stian Olstad

Joost Ringoot

unread,
Mar 16, 2017, 3:47:57 AM3/16/17
to Ansible Project
Thanks Andrew latham

This
python -c 'import yaml,sys;yaml.safe_load(sys.stdin)' < ansible/playbooks/apt/sssdconfig.yml
has no output, so I guess syntax is correct.

Thanks Kai Stian Olstad
-e should be key=value.

That fixes it, thanks
I also did a test changing
- hosts: "{{hosts}}"

into

- hosts: "{{destin}}"

in the yaml and it looks good from this point (I only need to make sure the destination machine is switched on)
ansible-playbook  ansible/playbooks/apt/sssdconfig.yml -e destin=cal-30

PLAY
[cal-30] ******************************************************************

TASK
[setup] *******************************************************************
fatal
: [cal-30]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: connect to host cal-30 port 22: Connection timed out\r\n", "unreachable": true}
    to
retry, use: --limit @/home/florence/ansible/playbooks/apt/sssdconfig.retry

PLAY RECAP
*********************************************************************
cal
-30                     : ok=0    changed=0    unreachable=1    failed=0  






Reply all
Reply to author
Forward
0 new messages