Ansible ad hoc commands only work as sudo unless i'm in the hosts directory - ansible

I'm trying to work through getting started with ansible. When I try to run ad hoc commands with ansible, such as ansible all -m ping I have to either be in the same folder as my hosts file ~/Development/ansible/ or use sudo. I'm getting ready to move forward with learning playbooks but I feel like this is going to come back as a problem at some point.
If I try to run the command outside of that folder without sudo I get this message
<XXX.XXX.XXX.XXX> ESTABLISH CONNECTION FOR USER: Joe
<XXX.XXX.XXX.XXX> REMOTE_MODULE ping
server | FAILED => Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 586, in _executor
exec_rc = self._executor_internal(host, new_stdin)
File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 789, in _executor_internal
return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)
File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 1036, in _executor_internal_inner
result = handler.run(conn, tmp, module_name, module_args, inject, complex_args)
File "/Library/Python/2.7/site-packages/ansible/runner/action_plugins/normal.py", line 62, in run
return self.runner._execute_module(conn, tmp, module_name, module_args, inject=inject, complex_args=complex_args)
File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 470, in _execute_module
) = self._configure_module(conn, module_name, args, inject, complex_args)
File "/Library/Python/2.7/site-packages/ansible/runner/__init__.py", line 1351, in _configure_module
module_path = utils.plugins.module_finder.find_plugin(module_name, module_suffixes)
File "/Library/Python/2.7/site-packages/ansible/utils/plugins.py", line 176, in find_plugin
full_paths = (os.path.join(path, f) for f in os.listdir(path))
OSError: [Errno 13] Permission denied: '/Users/Joe/library/Saved Application State/jp.co.trendy.sdformatter.savedState'
I've done a lot of searching around but haven't had much luck finding a solution.
Here is my ~/.ansible.cfg file
# config file for ansible -- http://ansible.com/
# ==============================================
# nearly all parameters can be overridden in ansible-playbook
# or with command line flags. ansible will read ANSIBLE_CONFIG,
# ansible.cfg in the current working directory, .ansible.cfg in
# the home directory or /etc/ansible/ansible.cfg, whichever it
# finds first
[defaults]
# some basic default values...
inventory = ~/Development/ansible/hosts
And, here is my hosts file
server ansible_ssh_host=XXX.XXX.XXX.XXX ansible_ssh_user=Joe ansible_ssh_private_key_file=~/.ssh/id_rsa

This appears to be not an Ansible problem but a permission issue with a software called SD Card Formatter from Trendy Corp. I don't know why this would be triggered when you run Ansible though.
The permissions of all the files in your library should get fixed by "repair permissions" in the Disk Utility Tool. Alternatively make sure the files and folders in /Users/Joe/library/Saved Application State/jp.co.trendy.sdformatter.savedState belong to user Joe: chown -R Joe:Joe /Users/Joe/library/Saved Application State/jp.co.trendy.sdformatter.savedState. If you don't care about this application, deleting the mentioned folder completely should do it too.

Related

JMeter-Taurus Docker Image Error - "No personal config found, creating one at /.bzt-rc"

I am trying to run a performance test within a Drone pipeline using JMeter-Taurus. I am pulling the latest (stable) image for blazemeter-taurus. However, when running the test in a pipeline the following error is returned.
This is the contents of the Dockerfile:
FROM blazemeter/taurus
RUN apt-get update && \
python3 -m pip install s3cmd
COPY . /bzt/
COPY config/90-artifacts-dir.json /etc/bzt.d/
COPY config/90-no-console.json /etc/bzt.d/
COPY .bzt-rc /root/.bzt-rc
RUN chown -R 1000:1000 /bzt && \
sed -i -e '/^assistive_technologies=/s/^/#/' /etc/java-*-openjdk/accessibility.properties
USER 1000
VOLUME ["/bzt"]
WORKDIR /bzt
UPDATE:
The "USER 1000" part has been removed. And the following line was added:
RUN chmod +x /bzt
But this is the error message returned:
Traceback (most recent call last):
File "/usr/local/bin/bzt", line 8, in <module>
sys.exit(main())
File "/usr/local/lib/python3.9/dist-packages/bzt/cli.py", line 676, in main
executor = CLI(parsed_options)
File "/usr/local/lib/python3.9/dist-packages/bzt/cli.py", line 56, in __init__
self.setup_logging(options)
File "/usr/local/lib/python3.9/dist-packages/bzt/cli.py", line 111, in setup_logging
file_handler = logging.FileHandler(options.log, encoding="utf-8")
File "/usr/lib/python3.9/logging/__init__.py", line 1146, in __init__
StreamHandler.__init__(self, self._open())
File "/usr/lib/python3.9/logging/__init__.py", line 1175, in _open
return open(self.baseFilename, self.mode, encoding=self.encoding,
PermissionError: [Errno 13] Permission denied: '/bzt/bzt.log'
######## TEST RUN STATUS : 1 #######
cat: /bzt/bzt_artifacts/bzt.log: No such file or directory
cat: /bzt/bzt_artifacts/error.jtl: No such file or directory
ls: cannot access '/bzt/bzt_artifacts/': No such file or directory
Taurus Docker image is root-oriented, here is the Dockerfile
I fail to see why Taurus is trying to create its config under /.bzt-rc, it may be some this "Drone pipeline" specifics, my expectation is that your test will fail because your user 1000 doesn't have write permissions to /tmp folder where Taurus stores its Artifacts

Seems Ansible failed to get the temp files

Ansible failed while running the tasks and referring file/folder not exists in the ansible temp folder of a target machine. It has been working fine and not sure why all of sudden it stopped working
changed : false
module_stderr : Shared connection to 10.131.132.11 closed.\r\n
module_stdout : Traceback (most recent call last):\r\n File \"/root/.ansible/tmp/ansible-tmp-1662460628.845051-105063944436404/AnsiballZ_setup.py\", line 113, in <module>\r\n try:\r\n File \"/root/.ansible/tmp/ansible-tmp-1662460628.845051-105063944436404/AnsiballZ_setup.py\", line 98, in _ansiballz_main\r\n json_params = f.read()\r\n File \"/usr/lib64/python2.7/tempfile.py\", line 321, in mkdtemp\r\n dir = gettempdir()\r\n File \"/usr/lib64/python2.7/tempfile.py\", line 265, in gettempdir\r\n tempdir = _get_default_tempdir()\r\n File \"/usr/lib64/python2.7/tempfile.py\", line 212, in _get_default_tempdir\r\n (\"No usable temporary directory found in %s\" % dirlist))\r\nIOError: [Errno 2] No usable temporary directory found in ['/tmp', '/var/tmp', '/usr/tmp', '/root']\r\n
msg : MODULE FAILURE\nSee stdout/stderr for the exact error
rc : 1
You can start by checking the permissions if they changed.
I think the disk is probably full. I had the same issue and it was the case.
You can type df -h
Also you can verify the inode.
You can type df -i

`ansible --version` command throws an ERROR

Good Day guys
I have installed ansible on my mac, it was successfully installed but then when I run the command ansible --version it throws me a n error:
Unhandled error:
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/ansible/config/manager.py", line 559, in update_config_data
value, origin = self.get_config_value_and_origin(config, configfile)
File "/Library/Python/2.7/site-packages/ansible/config/manager.py", line 503, in get_config_value_and_origin
value = ensure_type(value, defs[config].get('type'), origin=origin)
File "/Library/Python/2.7/site-packages/ansible/config/manager.py", line 124, in ensure_type
value = tempfile.mkdtemp(prefix=prefix, dir=value)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 339, in mkdtemp
_os.mkdir(file, 0700)
OSError: [Errno 13] Permission denied: '/Users/patrick/.ansible/tmp/ansible-local-37505vvsQNX'
Traceback (most recent call last):
File "/usr/local/bin/ansible", line 62, in <module>
import ansible.constants as C
File "/Library/Python/2.7/site-packages/ansible/constants.py", line 174, in <module>
config = ConfigManager()
File "/Library/Python/2.7/site-packages/ansible/config/manager.py", line 291, in __init__
self.update_config_data()
File "/Library/Python/2.7/site-packages/ansible/config/manager.py", line 571, in update_config_data
raise AnsibleError("Invalid settings supplied for %s: %s\n" % (config, to_native(e)), orig_exc=e)
ansible.errors.AnsibleError: Invalid settings supplied for DEFAULT_LOCAL_TMP: [Errno 13] Permission denied: '/Users/patrick/.ansible/tmp/ansible-local-37505vvsQNX'
Appreciate your help guys.
Check if this is similar to iiab/iiab/issue 1212:
After some more digging, I found the real source of this problem was hardcoded paths in ansible.cfg
Or the more recent ansible/galaxy-dev issue 107, which leads to PR 110:
The default ansible temp dir ~/.ansible/tmp is accessed by ansible-doc via the galaxy-importer.
This works OK in the galaxy-dev local env, but on the CI environment it attempts to create dir /.ansible/tmp and fails.
This PR changes the default ansible temp dir to /tmp/ansible which is outside the user home (and in the local env, /tmp has greater permissions)
Try and change DEFAULT_LOCAL_TMP to /tmp.
~/.ansible/tmp is probably root, so not accessible. chown it to user
I have disabled 'gathering' in ansible.cfg to fix the issue.
# gathering = False
Below error occurring before commenting this.
~ % ansible
Unhandled error:
Traceback (most recent call last):
File "/opt/homebrew/Cellar/ansible/6.6.0/libexec/lib/python3.10/site-packages/ansible/config/manager.py", line 627, in update_config_data
value, origin = self.get_config_value_and_origin(config, configfile)
File "/opt/homebrew/Cellar/ansible/6.6.0/libexec/lib/python3.10/site-packages/ansible/config/manager.py", line 586, in get_config_value_and_origin
raise AnsibleOptionsError('Invalid value "%s" for configuration option "%s", valid values are: %s' %
ansible.errors.AnsibleOptionsError: Invalid value "False" for configuration option "setting: DEFAULT_GATHERING ", valid values are: implicit, explicit, smart

HDFS: Errno 22 on attempt to edit an existing file in mounted NFS volume

Summary: I mounted HDFS nfs volume in OSX and it will not let me edit existing files. I can append and create files with content but not "open them with write flag".
Originally, I asked about a particular problem with JupyterLab failing to save notebooks into nfs mounted volumes but while trying to dig down to the roots, I realized (hopefully right) that it's about editing existing files.
I mounted HDFS nfs on OSX and I can access the files, read and write and whatnot. JupyterLab though can do pretty much everything but can't really save notebooks.
I was able to identify the pattern for what's really happening and the problem boils down to this: you can't open existing files in nfs volume for write:
This will work with a new file:
with open("rand.txt", 'w') as f:
f.write("random text")
But if you try to run it again (the file has been created now and the content is there), you'll get the following Exception:
---------------------------------------------------------------------------
OSError Traceback (most recent call last)
<ipython-input-15-94a46812fad4> in <module>()
----> 1 with open("rand.txt", 'w') as f:
2 f.write("random text")
OSError: [Errno 22] Invalid argument: 'rand.txt'
I am pretty sure the permissions and all are ok:
with open("seven.txt", 'w') as f:
f.write("random text")
f.writelines(["one","two","three"])
r = open("seven.txt", 'r')
print(r.read())
random textonetwothree
I can also append to files no problem:
aleksandrs-mbp:direct sasha$ echo "Another line of text" >> seven.txt && cat seven.txt
random textonetwothreeAnother line of text
I mount it with the following options:
aleksandrs-mbp:hadoop sasha$ mount -t nfs -o
vers=3,proto=tcp,nolock,noacl,sync localhost:/
/srv/ti/jupyter-samples/~Hadoop
Apache documentation suggests that NFS gateway does not support random writes. I tried looking at mount documentation but could not find anything specific that points to enforcing sequential writing. I tried playing with different options but it doesn't seem to help much.
This is the exception I get from JupyterLab when it's trying to save the notebook:
[I 03:03:33.969 LabApp] Saving file at /~Hadoop/direct/One.ipynb
[E 03:03:33.980 LabApp] Error while saving file: ~Hadoop/direct/One.ipynb [Errno 22] Invalid argument: '/srv/ti/jupyter-samples/~Hadoop/direct/.~One.ipynb'
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/services/contents/filemanager.py", line 471, in save
self._save_notebook(os_path, nb)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/services/contents/fileio.py", line 293, in _save_notebook
with self.atomic_writing(os_path, encoding='utf-8') as f:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 82, in __enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/services/contents/fileio.py", line 213, in atomic_writing
with atomic_writing(os_path, *args, log=self.log, **kwargs) as f:
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py", line 82, in __enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/services/contents/fileio.py", line 103, in atomic_writing
copy2_safe(path, tmp_path, log=log)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/services/contents/fileio.py", line 51, in copy2_safe
shutil.copyfile(src, dst)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
OSError: [Errno 22] Invalid argument: '/srv/ti/jupyter-samples/~Hadoop/direct/.~One.ipynb'
[W 03:03:33.981 LabApp] 500 PUT /api/contents/~Hadoop/direct/One.ipynb?1534835013966 (::1): Unexpected error while saving file: ~Hadoop/direct/One.ipynb [Errno 22] Invalid argument: '/srv/ti/jupyter-samples/~Hadoop/direct/.~One.ipynb'
[W 03:03:33.981 LabApp] Unexpected error while saving file: ~Hadoop/direct/One.ipynb [Errno 22] Invalid argument: '/srv/ti/jupyter-samples/~Hadoop/direct/.~One.ipynb'
This is what I see in the NFS logs at the same time:
2018-08-21 03:05:34,006 ERROR org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3: Setting file size is not supported when setattr, fileId: 16417
2018-08-21 03:05:34,006 ERROR org.apache.hadoop.hdfs.nfs.nfs3.RpcProgramNfs3: Setting file size is not supported when setattr, fileId: 16417
Not exactly sure what this means but if I understand the RFC, it should be part of implementation:
Servers must support extending the file size via SETATTR.
I understand the complexity behind mounting hdfs and letting clients write all they want while keeping these files distributed and maintain integrity. Is there though a compromise that would enable writes via nfs?

How to debug "ERROR! Unexpected Exception: Non-hexadecimal digit found" in Ansible and Vagrant?

I am facing a problem trying to run Vagrant with Ansible. Here is the error that I'm getting when I'm trying to run vagrant up or vagrant provision in terminal (git bash) on Windows 7:
ERROR! Unexpected Exception: Non-hexadecimal digit found
to see the full traceback, use -vvv
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
It happens because the Ansible-vault file .vault_pass is not hexadecimal (it is a string and it can't be changed). On computers of my coleagues it works normally, but on mine it doesn't.
The problematic string in .vault_pass file looks like DBAKWeG3KOr3jKjBDbAz.
I guess that the problem is something with Python, but I'm not sure and I don't know how to fix it.
When I try to add -vvv this is the resoult:
ERROR! Unexpected Exception: Non-hexadecimal digit found
the full traceback was:
Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 92, in
exit_code = cli.run()
File "/usr/lib/python2.7/dist-packages/ansible/cli/playbook.py", line 132, in run
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list=self.options.inventory)
File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 85, in __init__
self.parse_inventory(host_list)
File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 144, in parse_inventory
group.vars = combine_vars(group.vars, self.get_group_variables(group.name))
File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 509, in get_group_variables
self._vars_per_group[groupname] = self._get_group_variables(groupname, vault_password=vault_password)
File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 527, in _get_group_variables
vars = combine_vars(vars, self.get_group_vars(group))
File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 707, in get_group_vars
return self._get_hostgroup_vars(host=None, group=group, new_pb_basedir=new_pb_basedir)
File "/usr/lib/python2.7/dist-packages/ansible/inventory/__init__.py", line 746, in _get_hostgroup_vars
results = combine_vars(results, self._variable_manager.add_group_vars_file(base_path, self._loader))
File "/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py", line 578, in add_group_vars_file
(name, data) = self._load_inventory_file(path, loader)
File "/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py", line 535, in _load_inventory_file
_found, results = self._load_inventory_file(path=p, loader=loader)
File "/usr/lib/python2.7/dist-packages/ansible/vars/__init__.py", line 550, in _load_inventory_file
data = loader.load_from_file(path)
File "/usr/lib/python2.7/dist-packages/ansible/parsing/dataloader.py", line 113, in load_from_file
(file_data, show_content) = self._get_file_contents(file_name)
File "/usr/lib/python2.7/dist-packages/ansible/parsing/dataloader.py", line 172, in _get_file_contents
data = self._vault.decrypt(data)
File "/usr/lib/python2.7/dist-packages/ansible/parsing/vault/__init__.py", line 169, in decrypt
b_data = this_cipher.decrypt(b_data, self.b_password)
File "/usr/lib/python2.7/dist-packages/ansible/parsing/vault/__init__.py", line 674, in decrypt
data = unhexlify(data)
TypeError: Non-hexadecimal digit found
Ansible failed to complete successfully. Any error output should be
visible above. Please fix these errors and try again.
Just in case someone has the same problem, I had this issue when trying to manually decrypt a variable directly copied from a YAML file (or from the output of ansible-vault encrypt_string)
E.g:
Encrypting a string:
echo -n 'all that is gold does not glitter' | ansible-vault encrypt_string
Reading plaintext input from stdin. (ctrl-d to end input)
!vault |
$ANSIBLE_VAULT;1.1;AES256
61626566613637386434386364376236636636646263386561336463386132626335386335356463
3930303065646433346431383463653663356332306564310a653464313035383335633065666462
61303866343966613164623533323936383165623539623734316161373561383532326231623862
6439306562306433360a633038626233376262373561333630356662386462343566346565636364
64643961613064313964376266336330366566616435663130666135383739323962646563326336
3062636437636664363039383436306535303939323535353163
Trying to decrypt:
echo '$ANSIBLE_VAULT;1.1;AES256
61626566613637386434386364376236636636646263386561336463386132626335386335356463
3930303065646433346431383463653663356332306564310a653464313035383335633065666462
61303866343966613164623533323936383165623539623734316161373561383532326231623862
6439306562306433360a633038626233376262373561333630356662386462343566346565636364
64643961613064313964376266336330366566616435663130666135383739323962646563326336
3062636437636664363039383436306535303939323535353163' | ansible-vault decrypt --vault-password-file ./vault-env
[WARNING]: There was a vault format error in -: Vault format unhexlify error:
Non-hexadecimal digit found
ERROR! Vault format unhexlify error: Non-hexadecimal digit found for -
To fix it, just remove the YAML indentantion spaces at the beginning:
echo '$ANSIBLE_VAULT;1.1;AES256
61626566613637386434386364376236636636646263386561336463386132626335386335356463
3930303065646433346431383463653663356332306564310a653464313035383335633065666462
61303866343966613164623533323936383165623539623734316161373561383532326231623862
6439306562306433360a633038626233376262373561333630356662386462343566346565636364
64643961613064313964376266336330366566616435663130666135383739323962646563326336
3062636437636664363039383436306535303939323535353163' | ansible-vault decrypt --vault-password-file ./vault-env
Decryption successful
all that is gold does not glitter%
It has to do with Windows line endings at the end of encrypted file.
Just switch last line ending to Unix and save the file.
This issue may occur when encoded file contains carriage return (\r) symbol.
If you got files through git, you should configure git correctly - set core.eol = lf into .gitconfig
To add another variant how this can happen: trailing spaces at the end of the vaulted string will also do it:
mysql_pw: !vault |
$ANSIBLE_VAULT;1.1;AES256
35336630636134383938626366353162326236363966353535356361373465616364383336366536
6630373462316336333830643331376464633961643633380a623863373966323432646236306239
36326465343239343766363936653631643761646562306530363262633262323966623530373664
3239376534303565340a623262646132623033383964366438633964303633363430373463633033
3164 < spaces here
Depending on even/odd you might also get AnsibleVaultFormatError: Vault format unhexlify error: Odd-length string

Resources