ANSIBLE doesn't work - syntax check - ansible

I'm trying to setup on ansible my first playbooks.
Hovever... no matter which example I'm trying to test.. i receive similar error:
"xyz is not a valid attribute for a Play"
For example:
$ cat a2.yml
- name: Update and upgrade
become: true
apt:
upgrade: yes
update_cache: yes
$ ansible-playbook a2.yml --syntax-check
ERROR! 'apt' is not a valid attribute for a Play
The error appears to have been in '/home/pi/My/ansible/a2.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: Update and upgrade
^ here
Whats wrong?
PS.
$ ansible --version
ansible 2.4.2.0
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/pi/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
executable location = /usr/local/bin/ansible
python version = 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170124]

See Playbooks Intro documentation.
Your entry should be a task item.
---
- hosts: ...
tasks:
- name: Update and upgrade
become: true
apt:
upgrade: yes
update_cache: yes

Related

AWX Ansible - Dont read galaxy collections

I'm using AWX ansible ver 20.0 with kubernetes
My playbook:
---
- name: Install 7zip with offline package chocolatey
hosts: all
become: true
gather_facts: false
tasks:
- name: Create folder
win_file:
path: 'C:/Instalki'
state: directory
- name: Copy installer
become: true
win_copy:
src: "../playbooksWindows/installers/7zip.22.01.nupkg"
dest: "C:/Instalki/7zip.22.01.nupkg"
- name: install 7zip packages
win_chocolatey:
name: "7zip"
state: present
source: "C:/Instalki/7zip.22.01.nupkg"
- name : clear folder
win_file:
path: "C:/Instalki/7zip.22.01.nupkg"
state: absent
Error:
/usr/local/lib/python3.8/site-packages/paramiko/transport.py:236: CryptographyDeprecationWarning: Blowfish has been deprecated
"class": algorithms.Blowfish,
No config file found; using defaults
SSH password:
BECOME password[defaults to SSH password]:
ERROR! couldn't resolve module/action 'win_chocolatey'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/runner/project/playbooksWindows/Install_7zip.yml': line 27, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: install 7zip packages
^ here
My actual ansible collection on awx-ee container
# /usr/share/ansible/collections/ansible_collections
Collection Version
----------------------- -------
amazon.aws 4.1.0
ansible.posix 1.4.0
ansible.windows 1.11.1
awx.awx 21.5.0
azure.azcollection 1.13.0
community.vmware 2.9.1
google.cloud 1.0.2
kubernetes.core 2.3.2
openstack.cloud 1.9.1
ovirt.ovirt 2.2.3
redhatinsights.insights 1.0.7
theforeman.foreman 3.6.0
# /home/runner/.ansible/collections/ansible_collections
Collection Version
--------------------- -------
ansible.windows 1.11.1
chocolatey.chocolatey 1.3.0
I was installing collection with:
ansible-galaxy collection install chocolatey.chocolatey
Any ideas how to fix it on docker in ver AWX 17.01 everything works fine :/

Ansible with no action detected in task

I would like to check TLS/SSL certificate expiration date from Ansible.
After execute a valid YML (ansible-playbook TEST.yml) appears the following error:
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/scripts/Ansible/TEST.yml': line 15, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: check validity
^ here
This is the code:
- name: find cerfication files & expiration dates
hosts: 10.0.1.41
gather_facts: false
tasks:
- name: Find cert files under /etc/pki/tls/certs
find:
paths: /etc/pki/tls/certs
file_type: file
patterns: "*.crt"
recurse: yes
excludes: "localhost.crt"
register: find_result
- name: check validity
openssl_certificate_info:
path: "{{ item.path }}"
valid_at:
point_1: "+1w"
point_2: "+10w"
register: result
loop: "{{ find_result.files|flatten(levels=1) }}"
- debug: msg= "{{ result }}"
What's the exactly wrong?
My version:
[root#ansible Ansible]# ansible-playbook --version
ansible-playbook 2.6.20
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.6/site-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.6.6 (r266:84292, Jun 20 2019, 14:14:55) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)]
You are on a really old version of Ansible, I would recommend you to upgrade since your version had an end of support long ago (November 6, 2019).
Now, the module you are trying to use didn't exist in the version 2.6, that's the reason for the error raised by Ansible.
In the version 2.6, the way to check a certificate was to use the openssl_certificate module.
Something like:
- name: check validity
openssl_certificate:
path: "{{ item.path }}"
provider: assertonly
valid_at: 20171221162800Z
register: result
loop: "{{ find_result.files }}"

Ansible - How to run multiple tasks in a playbook

I'm new to ansible, and am attempting to run multiple tasks to install docker on a particular host group in an ansible playbook.
I have the following playbook...
---
- hosts: all
tasks:
- name: Update and upgrade apt packages
become: yes
apt:
upgrade: yes
update_cache: yes
cache_valid_time: 86400 #One day
- hosts: loadbalancer
become: yes
tasks:
- name: Install docker packages
apt:
name:
- 'apt-transport-https'
- 'ca-certificates'
- 'curl'
- 'software-properties-common'
state: present
- name: Add Docker official GPG key
apt-key:
url: https://download.docker.com/linux/ubuntu/gpg
This is the error I get when attempting to run the playbook...
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to be in '/home/vagrant/ansible/playbooks/hostname.yml': line 23, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Add Docker official GPG key
^ here
What am I doing wrong here?
Thanks,
It is not apt-key, it is apt_key. Please update and try again

How to caching Windows fact of ansible_fact to Redis?

I have ansible_fact caching using redis.
It is well gathering to cache of redis for RHEL/AIX/HPUX and using ansible_fact of playbook.
but, Windows fact is not caching to redis.
What problem? or What configuration will do?
My ansible version is
[user]$ ansible --version
ansible 2.8.0
config file = /home/user/.ansible.cfg
configured module search path = [u'/home/user/utility/module']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible
python version = 2.7.5 (default, Mar 26 2019, 22:13:06) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
My ansible.cfg is
$ ansible-config dump --only-changed
ANSIBLE_PIPELINING(/home/user/.ansible.cfg) = True
CACHE_PLUGIN(/home/user/.ansible.cfg) = redis
CACHE_PLUGIN_CONNECTION(/home/user/.ansible.cfg) = localhost:6379:0
CACHE_PLUGIN_TIMEOUT(/home/user/.ansible.cfg) = 86100
DEFAULT_FACT_PATH(/home/user/.ansible.cfg) = /home/user/facts.d
DEFAULT_GATHERING(/home/user/.ansible.cfg) = smart
DEFAULT_REMOTE_USER(/home/user/.ansible.cfg) = user
First playbook is well done (gather_fact: yes), gathering ansible_memtotal_mb for windows
- name: gather fact
hosts: windows
gather_facts: yes
tasks:
- name: insertline
lineinfile
path: "fact.html"
insertbefore: "</th></tr>"
line: "{{ ansible_memtotal_mb }}"
Second playbook is problem (gather_fact: no), it is not use fact for cache data and fatal error occur.
- name: gather fact
hosts: windows
gather_facts: no
tasks:
- name: insertline
lineinfile
path: "fact.html"
insertbefore: "</th></tr>"
line: "{{ ansible_memtotal_mb }}"
The ansible_memtotal_mb is not using cache data of redis, despite of using cache for redis.
TASK [(lineinfile) Save result DATA to HTML file. ****************************
Tuesday 30 July 2019 10:41:40 +0900 (0:00:00.613) 0:00:07.639 **********
fatal: [hostname]: FAILED! => {"msg": "The task includes an option with an
undefined variable. The error was: 'ansible_memtotal_mb' is undefined
The error appears to be in '/home/user/systeminfo.yml': line 73, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: (lineinfile) Save result DATA to HTML file. [\"{{ WEB_DIR }}\"]
^ 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 }}\"
"}

Ansible YAML syntax error in simple playbook

I have my first playbook and it fails. I assume it's a syntax error but as I'm not a coder I have no idea why YAML fails? Is it to do with spacing?
Here is what I have:
---
- name: Update all packages to the latest version
become: true
apt:
update_cache: yes
upgrade: dist
- name: Remove useless packages from the cache
apt:
autoclean: yes
- name: Remove dependencies that are no longer required
apt:
autoremove: yes
ERROR! Syntax Error while loading YAML.
The error appears to have been in '/home/pi/playbooks/update-apt.yml': line 3, column 11, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: Update all packages to the latest version
become: true
^ here
Firstly: this is not a playbook, because it doesn't contain plays (which must contain hosts declaration), but tasks.
Secondly: your indentation is terribly broken -- it is critical in YAML to keep declarations aligned properly (that said, the error you see is not a YAML syntax error, but an Ansible error resulting from improper data defined in a correctly written YAML file).
If you want to run it locally, it should look more or less like this:
---
- hosts: localhost
connection: local
tasks:
- name: Update all packages to the latest version
become: true
apt:
update_cache: yes
upgrade: dist
autoclean: yes
autoremove: yes

Resources