How read file vars to make global bars for roles? - ansible

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...

Related

Ansible/AWX/Tower ERROR! Neither the collection requirement entry key 'name', nor 'source' point to a concrete resolvable collection artifact

I am trying to run a basic playbook using AWX but the playbook is always failing in the
fetch galaxy collections from collections/requirements.(yml/yaml) task in the requirements.yml file. The error that I am getting is
ERROR! Neither the collection requirement entry key 'name', nor 'source' point to a concrete resolvable collection artifact. Also 'name' is not an FQCN. A valid collection name must be in the format .. Please make sure that the namespace and the collection name contain characters from [a-zA-Z0-9_] only.
Tip: Make sure you are pointing to the right subdirectory — /var/lib/awx/projects/.__awx_cache/_8__testproject/stage/tmp/ansible-local-640q06qxv5r/tmpn_dk6jym/pylibsshmg6_wq45 looks like a directory but it is neither a collection, nor a namespace dir.
Version information:
ansible [core 2.13.1]
config file = None
configured module search path = ['/Users/garandre/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/ansible
ansible collection location = /Users/garandre/.ansible/collections:/usr/share/ansible/collections
executable location = /Library/Frameworks/Python.framework/Versions/3.10/bin/ansible
python version = 3.10.4 (v3.10.4:9d38120e33, Mar 23 2022, 17:29:05) [Clang 13.0.0 (clang-1300.0.29.30)]
jinja version = 3.1.2
libyaml = False
My requiremnets.yml file looks like this:
---
collections:
- name: https://git#github.com/ansible/pylibssh.git
type: git
version: '0.4.0'
- name: https://git#github.com/ansible-collections/cisco.iosxr
type: git
version: '3.2.0'
Most of the things that I have tried have been based on the documentation here:
https://docs.ansible.com/ansible/latest/galaxy/user_guide.html#installing-a-collection-from-a-git-repository.
Any help is appreciated!! Thanks!

how to make ansible work on remote servers which has python 2.4

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

Unable to update xml element value with ansible-playbook

I am using below playbook to update specific element value in xml file and its throwing error. I have installed python-lxml module as well as ansible version 2.7.8
---
- name: Set element
xml:
path: /home/emsuser/appD_agent_master/machineagent/machine_agent/conf/controller-info.xml
xpath: /controller-info/application-name
value: "Vicom Enterprise blackout Manager"
...
responce:
ERROR! 'xml' is not a valid attribute for a Play
The error appears to have been in '/home/emsuser/playbooks/editMechineAgentConf.yml': line 2, column 4, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
---
- name: Set element
^ here
I am not sure where I am doing mistake. Please help me out . I am new to ansible.
Your code is not a playbook, it's a task file.
In a playbook, you have a tasks: section listing your tasks.
Take a look at the Playbooks intro documentation.

Ansible Error reading config file: File contains no section headers

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

Ansible archive module "no action detected in task"

I want to use the archive module of ansible but it is unfortunately not working. I have the following version installed: ansible 2.3.0 (devel 2131eaba0c)
my playbook looks like this:
- archive: path="{{path_dir}}" dest="{{dest_dir}}/foo.zip" format=zip
The output looks like this:
"failed": true, "reason": "no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/prj/sndbox1/app/jenkins/jobs/release/workspace/tasks/build_rpclient.yml': line 125, column 3, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- archive: path="{{path_dir}}" dest="{{dest_dir}}/foo.zip" format=zip
^ 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 }}"
As far as I understood the doc, the extra modules are shipped within ansible, so I assume I don't need to separately install this module.
However, what am I doing wrong? Is there any configuration I need to change in order to tell ansible where to look for the extra modules?
Thanks in advance!
Edit: Included the the full log message
Edit 2:
I tried to put the archive.py directly into my working directory --> [library]/archive.py
Now I get the following error:
"failed": true, "msg": "Could not find imported module support code for archive. Looked for either get_exception or pycompat24"
I have the same use case here, I'm using Ansible version 2.2.0.0. Installed via brew on MacOS sierra.
I've managed to solve the issue by adding the following into my local ansible.cfg file.
On defautls section, you must change the library entry:
[defaults]
library = /usr/local/Cellar/ansible/2.2.0.0_2/libexec/lib/python2.7:library
If you have a different setup, check:
pip show ansible
/usr/share/ansible if you are on Linux machine.

Resources