kwoodson / ansible-role-yedit

Ansible Role for Yaml editing
164 stars 62 forks source link

Reports failed, but is successful #67

Open jeff-cook opened 5 years ago

jeff-cook commented 5 years ago

When running the following code it reports as failed. The value is correctly updated.

When the 'hash' already has the matching value it reports "OK" or unchanged.

- name: "manage {{username}} in internal_users.yml file"
  yedit:
    src: "{{od4es_internal_users_file}}"
    key: "{{username}}.hash"
    value: "{{ userhash }}"
The full traceback is:
Traceback (most recent call last):
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1554493645.47-213942729249153/AnsiballZ_yedit.py", line 113, in <module>
    _ansiballz_main()
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1554493645.47-213942729249153/AnsiballZ_yedit.py", line 105, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/vagrant/.ansible/tmp/ansible-tmp-1554493645.47-213942729249153/AnsiballZ_yedit.py", line 48, in invoke_module
    imp.load_module('__main__', mod, module, MOD_DESC)
  File "/tmp/ansible_yedit_payload_p5Dtgd/__main__.py", line 969, in <module>
  File "/tmp/ansible_yedit_payload_p5Dtgd/__main__.py", line 961, in main
  File "/tmp/ansible_yedit_payload_p5Dtgd/__main__.py", line 893, in run_ansible
  File "/tmp/ansible_yedit_payload_p5Dtgd/__main__.py", line 446, in write
  File "/tmp/ansible_yedit_payload_p5Dtgd/__main__.py", line 422, in _write
OSError: [Errno 22] Invalid argument

fatal: [localhost]: FAILED! => {
    "changed": false, 
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1554493645.47-213942729249153/AnsiballZ_yedit.py\", line 113, in <module>\n    _ansiballz_main()\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1554493645.47-213942729249153/AnsiballZ_yedit.py\", line 105, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/vagrant/.ansible/tmp/ansible-tmp-1554493645.47-213942729249153/AnsiballZ_yedit.py\", line 48, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/tmp/ansible_yedit_payload_p5Dtgd/__main__.py\", line 969, in <module>\n  File \"/tmp/ansible_yedit_payload_p5Dtgd/__main__.py\", line 961, in main\n  File \"/tmp/ansible_yedit_payload_p5Dtgd/__main__.py\", line 893, in run_ansible\n  File \"/tmp/ansible_yedit_payload_p5Dtgd/__main__.py\", line 446, in write\n  File \"/tmp/ansible_yedit_payload_p5Dtgd/__main__.py\", line 422, in _write\nOSError: [Errno 22] Invalid argument\n", 
    "module_stdout": "", 
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", 
    "rc": 1
}

The file being updated is https://github.com/opendistro-for-elasticsearch/security/blob/master/securityconfig/internal_users.yml

jeff-cook commented 5 years ago

I have a work around. Just run it twice and ignore errors for the first run. I don't like it, but it did get my YAML file with the correct values, so I could keep testing.

- name: "manage {{username}}.hash in internal_users.yml file"
  yedit:
    src: "{{od4es_internal_users_file}}"
    key: "{{username}}.hash"
    value: "{{ userhash }}"
  ignore_errors: true
  tags:
    - stack
- name: "manage {{username}}.hash in internal_users.yml file"
  yedit:
    src: "{{od4es_internal_users_file}}"
    key: "{{username}}.hash"
    value: "{{ userhash }}"
fdammeke commented 3 years ago

I'm also seeing this error on RHEL8 using: ansible + python 3.6 or 3.9:

ansible-playbook [core 2.11.4]
  config file = /vagrant/openshift4-ansible-installer/ansible.cfg
  configured module search path = ['/home/vagrant/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/vagrant/.local/lib/python3.9/site-packages/ansible
  ansible collection location = /home/vagrant/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.9.2 (default, Mar  5 2021, 01:49:45) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
  jinja version = 3.0.1
  libyaml = True

I don't have the error on OSX using: ansible + python 3.9:

ansible-playbook [core 2.11.2]
  config file = /Users/xx/gitrepo/private/puppet-monorepo/openshift4-ansible-installer/ansible.cfg
  configured module search path = ['/Users/xx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
  ansible collection location = /Users/xx/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.9.5 (default, May  4 2021, 03:36:27) [Clang 12.0.0 (clang-1200.0.32.29)]
  jinja version = 3.0.1
  libyaml = True
fdammeke commented 3 years ago

The correlation between @jeff-cook s issue and mine is that we both use vagrant and probably are both using the /vagrant folder to run the playbook.

Vagrant uses a vboxfs filesystem mount of a local os filesystem into the vagrant box. I assume that it doesn't support os.fsync like other network based filesystems.

vagrant on /vagrant type vboxsf (rw,nodev,relatime,iocharset=utf8,uid=65535,gid=65535)

Ref: https://github.com/kwoodson/ansible-role-yedit/blob/master/library/yedit.py#L417-L434

The code runs fine within vagrant on a regular xfs/ext/.. filesystem.