解决salt gitfs lock无法正常更新的问题

Solve 'salt gitfs lock'

Posted by alovn on September 4, 2021

Salt 支持 gitfs 将pillar配置存储到 Git 远程仓库中进行版本控制, 更易于管理。
当提交更新至远程 Git 仓库后, 需要手动在 Master 执行如下操作:

1
> salt-run fileserver.update  

或者等待一段时间,由 Master 进行更新 (默认更新间隔为 60s, 可以通过 Master 配置文件 loop_interval 选项进行调整).

不过也有可能会因为网络等问题导致git pull失败而无法更新,这时需要先查看日志确认一下问题:

1
> tail /var/log/salt/master

[WARNING ]Update lock file is present for git_pillar remote ‘env [email protected]:xxx/xxx.git’, skipping. If this warning persists, it is possible that the update process was interrupted, but the lock could also have been manually set. Removing /var/cache/salt/master/git_pillar/0f000bcaf5a96f37138eedeb42cdb25fb7b760b049ea4b1fe8b96badee448817/.git/update.lk or running ‘salt-run cache.clear_git_lock git_pillar type=update’ will allow updates to continue for this remote.

通过日志可以看到git文件处于lock状态,需要执行以下命令解除锁定:

1
> salt-run cache.clear_git_lock git_pillar type=update

然后再执行以下命令进行git仓库更新:

1
> salt-run fileserver.update