In Ansible 2.4, I'm getting this deprecation warning:
[DEPRECATION WARNING]: [defaults]hostfile option, The key is misleading as it can also be a list of hosts, a directory or a list of
paths . This feature will be removed in version 2.8. Deprecation warnings can be disabled by setting deprecation_warnings=False in
ansible.cfg.
For the life of me, I cannot figure out what this means. Anybody know?
In my ansible.cfg file, I had a line like
hostfile = ./inventory
That needs to be changed to
inventory = ./inventory
Related
I am trying to use bitwise operation inside my ansible playbooks. As sugegsted in this post (How to perform bitwise operations in Ansible?), I have created the .py file for "bitwise or" filter and placed under default filterplugin dir
/usr/share/ansible/plugins/filter
1)The ansible ansible.cfg file is edited to specify the filter plugin path.
filter_plugins = /usr/share/ansible/plugins/filter
2)Ansible version on controller node is: 3.6.10
But unfortunately playbook is not able to find the new defined filter. I am not sure if I am missing anything. Is there anything else I need to do?
Any help with this is appreciate.
The filter plugin I tried is working now. There was a small coding issue inside my filter python file, which was reported by playbook run logs on the console, that I didn't spot.
After carefully looking into the logs, I could fix the coding issue and, after that, the filter operation was found from the filter_plugin path that was specified in the ansible.cfg file.
filter_plugins = /usr/share/ansible/plugins/filter
There was no more setting needed apart from specifying the filter path in ansible.cfg.
Making my question more meaningful...
Ansible controller server :
ansible 2.4.2.0
Python 2.7.5
Managed nodename (goldville):
Python 2.4.2
When i run #ansible goldville -m ping
I get the below error
File "/tmp/ansible_RSjze6/ansible_module_ping.py", line 8\r\n from future import absolute_import, division, print_function\r\nSyntaxError: future feature absolute_import is not defined\r\n"
How can i use this node with python 2.4.2 to run playbooks from controller.
[py24-hosts]
goldville-py3 ansible_host=goldville
[py23-hosts:vars]
ansible_python_interpreter=/usr/bin64/python2.4
When i run below it gave error
#ansible goldville -m ping
Failed to parse /home/ansible/ansiblehosts with ini plugin: /home/ansible/ansiblehosts:4: Section [py23-hosts:vars] not valid
for undefined group: py23-hosts
If you want use python 2.4 some hosts or groups, set the ansible_python_interpreter inventory variable, try something like this:
[py24-hosts]
goldville-py3 ansible_host=goldville
[py24-hosts:vars]
ansible_python_interpreter=/usr/bin64/python2.4
But if you want use python2.4 for all you must set interpreter_python key in the defaults section in the configuraion file ansible.cfg
Docuementation:
https://docs.ansible.com/ansible/latest/reference_appendices/interpreter_discovery.html
How I load hosts.yml file from started playbook and the values are used in the roles.
I launch:
$ ansible-playbook proxy_squid.yml -i ./group_vars/hosts.yml -vvvvv
But I receive:
ansible-playbook 2.5.1
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/home/user/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.17 (default, Jul 20 2020, 15:37:01) [GCC 7.5.0]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /home/user/repo/Iso27001/ansible/group_vars/hosts.yml inventory source with yaml plugin
Read vars_file './group_vars/vault_data.yml'
Read vars_file './group_vars/vault_ip.yml'
Read vars_file './group_vars/hosts.yml'
Loading callback plugin default of type stdout, v2.0 from /usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.pyc
PLAYBOOK: proxy_squid.yml *****************************************************************
1 plays in proxy_squid.yml
Read vars_file './group_vars/vault_data.yml'
Read vars_file './group_vars/vault_ip.yml'
Read vars_file './group_vars/hosts.yml'
ERROR! The field 'hosts' has an invalid value, which includes an undefined variable. The error was: 'h_tmpvm' is undefined
The error appears to have been in '/home/user/repo/ansible/proxy_squid.yml': line 3, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Declaring conf
^ here
Thanks a lot!!
I found... python was not installed in the target host. Sorry...
SUMMARY
As per documentation for Ansible Configuration Settings, we can place ansible.cfg in current directory of the project we are working on and Ansible will search for a config file in the order specified in link above.
However, it appears that ansible is unable to correctly parse ansible.cfg file within my project directory. I am not sure but I think it has to be with the Ini ConfigParser
ANSIBLE VERSION
ansible 2.6.3
config file = /Users/pnotes/Code/Terraform/Blog/ansible/ansible.cfg
configured module search path = ['/Users/pnotes/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Users/pnotes/.pyenv/versions/3.6.4/lib/python3.6/site-packages/ansible
executable location = /Users/pnotes/.pyenv/versions/3.6.4/bin/ansible
python version = 3.6.4 (default, Feb 26 2018, 21:07:35) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
CONFIGURATION
output of "ansible-config dump --only-changed"
Error reading config file (/Users/pnotes/Code/Terraform/Blog/terraform/ansible.cfg): File contains no section headers.
file: '/Users/pnotes/Code/Terraform/Blog/terraform/ansible.cfg', line: 3
'vault_password_file = ~/.vault_pass.txt\n'
OS / ENVIRONMENT
macOS High Sierra
contents of terraform/ansible.cfg:
# If set, configures the path to the Vault password file as an
# alternative to specifying --vault-password-file on the command
# line.
vault_password_file = ~/.vault_pass.txt
n
Note: when project_directory/terraform/ansible.cfg is commented out, ansible uses ~/.ansible.cfg and is able to decrypt encrypted files.
EXPECTED RESULTS
I expect playbook to decrypt all encrypted vars using the ansible vault password saved in the path provide in the configuration file (ansible.cfg) provided in the project directory.
ACTUAL RESULTS
I get the error below:
Error: Error applying plan:
1 error(s) occurred:
* linode_linode.base: Error running command 'sleep 30; ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u root --ask-pass -i '172.104.29.185,' ../ansible/provision.yml --extra-vars 'ip=000.111.22.185' -vvvv': exit status 5. Output: Error reading config file (/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg): File contains no section headers.
file: '/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg', line: 3
'vault_password_file = ~/.vault_pass.txt\n'
Can someone please explain why I keep getting the error **exit status 5. Output: Error reading config file (/Users/pnotes/Code/Terraform/Test/terraform/ansible.cfg): File contains no section headers.
I also tried looking for info on how ansible generates the default /etc/ansible.cfg file but can't seem to track it down (I use python in a limited capacity so this might be why I am having a hard time with this)
Would really appreciate it.
ansible.cfg is supposed to be divided into sections with headers of the form [section_name]. The vault_password_file option, like the majority of the configuration options, belongs to the [defaults] section, so your ansible.cfg needs to look like:
[defaults]
vault_password_file = ~/.vault_pass.txt
I have some continuous integration checks which run a few ansible-playbook commands. Each playbook may be running many plays, including numerous large roles.
Every now and then, somebody introduces some change that causes a warning when ansible-playbook runs, e.g. something like this:
[WARNING]: when statements should not include jinja2 templating delimiters
such as {{ }} or {% %}. Found: "{{ some_variable}}" not in
some_result.stdout
or:
[WARNING]: Consider using unarchive module rather than running tar
or some deprecation warnings like:
[DEPRECATION WARNING]: ec2_facts is kept for backwards compatibility but usage
is discouraged. The module documentation details page may explain more about
this rationale.. This feature will be removed in a future release. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
and so on. Sometimes these warnings pop up when we upgrade ansible versions. Regardless of why they happen, I would really like for some way to have the ansible-playbook command fail loudly when it causes one of these warnings, instead of quietly proceeding on and having my CI check be successful. Is there any way to do this? I'm using ansible 2.4.3 currently.
I find lots of discussion about ways to hide these warnings, but haven't found anything about promoting them to hard errors.
I have the exact same problem. My workaround is:
run the playbook with --check and 'tee' to a temporary file
do some grep-magic to filter out 'WARNING]:'
do some grep-sed-magic to filter out results that are not zero (except ok/skipped)
I know it is not ideal, so if you came with a nice solution please share :-)
There is an option any_errors_fatal in ansible.cfg, what about putting
any_errors_fatal = True
To hide such [DEPRECATION WARNING] as stated you can
"disabled by setting deprecation_warnings=False in ansible.cfg."
But this may not be ideal, As in future you have no visibility of what may change or being depreciated.
If you are absolutely sure that you can ignore such a warning, You can use::
args:
warn: false
Or modify your code as suggested in the warning message.
else
If you want to raise error for any warnings, You could register the result and apply failed_when like below example.
- hosts: localhost
gather_facts: false
tasks:
- name: Fail if there is any warnings
shell: touch a.txt
register: result
failed_when: result.warnings is defined`
What for? Do they interfere with the implementation of the playbook? Most likely it is not. Just fix the playbook code.
Such a warning to remove as I understood it is either impossible or very difficult (in any case, it did not work for me when I tried):
[WARNING]: when statements should not include jinja2 templating delimiters
such as {{ }} or {% %}. Found: "{{ some_variable}}" not in
some_result.stdout
Just use:
some_variable not in some_result.stdout
In the "when" conditions it is not necessary to set {{}} to get the variable value
Personally, I prefer to search through "find":
some_result.stdout.find(some_variable) == -1
This warning:
[DEPRECATION WARNING]: ec2_facts is kept for backwards compatibility but usage
is discouraged. The module documentation details page may explain more about
this rationale.. This feature will be removed in a future release. Deprecation
warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
can be removed from output by setting:
deprecation_warnings = false
in the file ansible.cfg
This warn:
[WARNING]: Consider using unarchive module rather than running tar
Easy to remove if you use the module ansible instead of tar in "command":
unarchive: src=file.tgz dest=/opt/dest