Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synchronize reports changed_when when excluded file has changed #542

Open
martin-braun opened this issue May 6, 2024 · 0 comments
Open

Comments

@martin-braun
Copy link

martin-braun commented May 6, 2024

SUMMARY

changed_when seems not to respect excluded files via rsync_opts. If the given file was changed, despite not being synchronized when running the playbook, synchronize will result in changed_when = True.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ansible.posix.synchronize

ANSIBLE VERSION
ansible [core 2.16.3]
  config file = /Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg
  configured module search path = ['/Users/marty/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/9.2.0/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/marty/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.12.1 (main, Dec  7 2023, 20:45:44) [Clang 15.0.0 (clang-1500.1.0.2.5)] (/usr/local/Cellar/ansible/9.2.0/libexec/bin/python)
  jinja version = 3.1.3
COLLECTION VERSION

# /usr/local/Cellar/ansible/9.2.0/libexec/lib/python3.12/site-packages/ansible_collections
Collection    Version
------------- -------
ansible.posix 1.5.4
CONFIGURATION
ANSIBLE_NOCOWS(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = True
COLOR_HIGHLIGHT(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = magenta
CONFIG_FILE() = /Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg
DEFAULT_GATHERING(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = explicit
DEFAULT_HOST_LIST(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = ['/Users/marty/.sources/github.com/martin-braun/gf-server/inventory.cfg']
DEFAULT_LOG_PATH(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = /Users/marty/.sources/github.com/martin-braun/gf-server/ansible.log
DEFAULT_STRATEGY(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = linear
DIFF_ALWAYS(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = True
DIFF_CONTEXT(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = 5
EDITOR(env: EDITOR) = vim
PERSISTENT_COMMAND_TIMEOUT(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = 15
PERSISTENT_CONNECT_TIMEOUT(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = 15
RETRY_FILES_ENABLED(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = True
RETRY_FILES_SAVE_PATH(/Users/marty/.sources/github.com/martin-braun/gf-server/ansible.cfg) = /Users/marty/.sources/github.com/martin-braun/gf-server/ansible/.retry

OS / ENVIRONMENT

macOS -> Debian

STEPS TO REPRODUCE

Have a project that contains a playbook.yml and a few other files. Now in your playbook define a task to synchronize the project onto a server in production:

    - name: Ensure app files
      ansible.posix.synchronize:
        src: "./"
        dest: "/var/www/ansible-test"
        recursive: True
        delete: True
        rsync_opts:
          - "'--exclude=/playbook.yml'"

This will synchronize all files, but the playbook.yml. It works. On continues calls changed_when = False. But now change something in the playbook.yml and re-run it.

EXPECTED RESULTS

It should changed_when = False regardless of me changing the file or not.

Verbose output:

changed: {"ansible_loop_var": "item", "changed": true, "cmd": "/usr/local/bin/rsync --delay-updates -F --compress --delete-after --archive --rsh='/usr/bin/ssh -S none -o StrictHostKe
yChecking=no -o UserKnownHostsFile=/dev/null' '--exclude=/playbook.yml' --out-format='<<CHANGED>>%i %n%L' /Users/marty/.sources/github.com/martin-braun/gf-server gf:/var/www/ansible-test/.", "item": ".", "msg": "<f.st..
..... gf-server/playbook.yml\n", "rc": 0, "stdout_lines": ["<f.st....... gf-server/playbook.yml"]}
ACTUAL RESULTS

It will now result in changed_when = True, although the playbook.yml itself is skipped by --exclude.

ADDITIONAL INFORMATION

My local ansible.cfg:

[defaults]
inventory = inventory.cfg
gathering = explicit
log_path = ansible.log
strategy = linear
nocows = 1
retry_files_enabled = True
retry_files_save_path = ./ansible/.retry

[ssh_connection]
scp_if_ssh = True
transfer_method = scp
retries = 1

[persistent_connection]
connect_timeout = 15
command_timeout = 15

[colors]
highlight = magenta

[diff]
always = True
context = 5

Please note I call setup in my playbook above the task, so facts are gathered regardless of me specifying explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant