An Ansible playbook run failed on a particular task which was using the "stat" module and register the result in a variable:
# Check if default settings already exist
- name: MARIADB - Check if default settings 90-ourdefaults.cnf exists
stat:
path: /etc/mysql/mariadb.conf.d/90-ourdefaults.cnf
register: 90ourdefaults
The following playbook run failed:
TASK [MARIADB - Check if default settings 90-ourdefaults.cnf exists] **************************************************
fatal: [server]: FAILED! => {"msg": "Invalid variable name in 'register' specified: '90ourdefaults'"}
The reason is actually quite simple but can be overlooked very easily. From the Ansible variable documentation:
Not all strings are valid Ansible variable names. A variable name can only include letters, numbers, and underscores. Python keywords or playbook keywords are not valid variable names. A variable name cannot begin with a number.
There we have it: A variable name cannot begin with a number!
Slightly adjust the task and use another variable name (remove the leading number) in the register part:
# Check if default settings already exist
- name: MARIADB - Check if default settings 90-ourdefaults.cnf exists
stat:
path: /etc/mysql/mariadb.conf.d/90-ourdefaults.cnf
register: ourdefaults
And the Playbook now runs through:
TASK [MARIADB - Check if default settings 90-ourdefaults.cnf exists] **************************************************
ok: [server]
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder