模塊嵌牺、文件同步問題

一打洼、salt 倉(cāng)庫(kù)目錄配置

file_roots:
  base:
    - /data/salt/
  dev:
    - /data/salt/dev/services
    - /data/salt/dev/states
  prod:
    - /data/salt/prod/services
    - /data/salt/prod/states
  winrepo:
    - /data/salt/winrepo/files
    - /data/salt/winrepo/states

二、倉(cāng)庫(kù)目錄結(jié)構(gòu)

[root@salt-master01 salt]# tree -a
.
├── _modules
│   ├── mygit.py
│   └── net_ops.py
└── winrepo
    ├── files
    │   ├── .gitconfig
    │   ├── .git-credentials
    │   ├── git-lfs-windows-2.0.2.exe
    │   └── iiscrash.reg
    └── states
        └── git-config.sls

4 directories, 7 files

目前先只建了 winrepo

三逆粹、sls 配置

[root@salt-master01 salt]# cat winrepo/states/git-config.sls 
C:\Windows\System32\config\systemprofile\.gitconfig:
  file.managed:
    - source: salt://winrepo/files/.gitconfig

C:\Windows\System32\config\systemprofile\.git-credentials:
  file.managed:
    - source: salt://winrepo/files/.git-credentials

四募疮、用法

winrepo.states.git-config 即是 按照目錄結(jié)構(gòu)

[root@salt-master01 salt]# salt "net-api05.ycf.com" state.sls winrepo.states.git-config
net-api05.ycf.com:
----------
          ID: C:\Windows\System32\config\systemprofile\.gitconfig
    Function: file.managed
      Result: True
     Comment: File C:\Windows\System32\config\systemprofile\.gitconfig is in the correct state
     Started: 12:07:57.960000
    Duration: 102.0 ms
     Changes:   
----------
          ID: C:\Windows\System32\config\systemprofile\.git-credentials
    Function: file.managed
      Result: True
     Comment: File C:\Windows\System32\config\systemprofile\.git-credentials is in the correct state
     Started: 12:07:58.063000
    Duration: 13.0 ms
     Changes:   

Summary for net-api05.ycf.com
------------
Succeeded: 2
Failed:    0
------------
Total states run:     2
Total run time: 115.000 ms

或者直接使用

salt "net-api05.ycf.com" state.highstate

但要求有top.sls,因?yàn)?stat.highstate 默認(rèn)是讀取 base 倉(cāng)庫(kù)下的top.sls 文件

[root@salt-master01 salt]# cat top.sls 
winrepo:
  '*':
    - git-config

但是配置了top.sls 之后僻弹,saltutil.sync_modules 模塊同步就失效了

查看文檔:

[root@salt-master01 salt]# sudo salt "net-api05.ycf.com" sys.doc saltutil.sync_modules
saltutil.sync_modules:

    New in version 0.10.0

    Sync execution modules from ``salt://_modules`` to the minion

    saltenv
        The fileserver environment from which to sync. To sync from more than
        one environment, pass a comma-separated list.

        If not passed, then all environments configured in the :ref:`top files
        <states-top>` will be checked for execution modules to sync. If no top
        files are found, then the ``base`` environment will be synced.

    refresh : True
        If ``True``, refresh the available execution modules on the minion.
        This refresh will be performed even if no new execution modules are
        synced. Set to ``False`` to prevent this refresh.

    .. important::

        If this function is executed using a :py:func:`module.run
        <salt.states.module.run>` state, the SLS file will not have access to
        newly synced execution modules unless a ``refresh`` argument is
        added to the state, like so:

            load_my_custom_module:
              module.run:
                - name: saltutil.sync_modules
                - refresh: True

        See :ref:`here <reloading-modules>` for a more detailed explanation of
        why this is necessary.

    extmod_whitelist : None
        comma-seperated list of modules to sync

    extmod_blacklist : None
        comma-seperated list of modules to blacklist based on type

    CLI Example:

        salt '*' saltutil.sync_modules
        salt '*' saltutil.sync_modules saltenv=dev
        salt '*' saltutil.sync_modules saltenv=base,dev

原因是saltutil.sync_modules 模塊同步會(huì)默認(rèn)讀取top.sls阿浓,根據(jù)配置的倉(cāng)庫(kù)來同步模塊,上面top.sls 配置的是winrepo蹋绽,不是base芭毙,所以同步不了base 倉(cāng)庫(kù)目錄下的_modules 文件

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市卸耘,隨后出現(xiàn)的幾起案子退敦,更是在濱河造成了極大的恐慌,老刑警劉巖蚣抗,帶你破解...
    沈念sama閱讀 218,386評(píng)論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件侈百,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡翰铡,警方通過查閱死者的電腦和手機(jī)钝域,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評(píng)論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來锭魔,“玉大人例证,你說我怎么就攤上這事∶耘酰” “怎么了织咧?”我有些...
    開封第一講書人閱讀 164,704評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)漠秋。 經(jīng)常有香客問我烦感,道長(zhǎng),這世上最難降的妖魔是什么膛堤? 我笑而不...
    開封第一講書人閱讀 58,702評(píng)論 1 294
  • 正文 為了忘掉前任手趣,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘绿渣。我一直安慰自己朝群,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,716評(píng)論 6 392
  • 文/花漫 我一把揭開白布中符。 她就那樣靜靜地躺著姜胖,像睡著了一般。 火紅的嫁衣襯著肌膚如雪淀散。 梳的紋絲不亂的頭發(fā)上右莱,一...
    開封第一講書人閱讀 51,573評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音档插,去河邊找鬼慢蜓。 笑死,一個(gè)胖子當(dāng)著我的面吹牛郭膛,可吹牛的內(nèi)容都是我干的晨抡。 我是一名探鬼主播,決...
    沈念sama閱讀 40,314評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼则剃,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼耘柱!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起棍现,我...
    開封第一講書人閱讀 39,230評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤调煎,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后己肮,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體士袄,經(jīng)...
    沈念sama閱讀 45,680評(píng)論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,873評(píng)論 3 336
  • 正文 我和宋清朗相戀三年朴肺,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了窖剑。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片坚洽。...
    茶點(diǎn)故事閱讀 39,991評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡戈稿,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出讶舰,到底是詐尸還是另有隱情鞍盗,我是刑警寧澤,帶...
    沈念sama閱讀 35,706評(píng)論 5 346
  • 正文 年R本政府宣布跳昼,位于F島的核電站般甲,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏鹅颊。R本人自食惡果不足惜敷存,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,329評(píng)論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧锚烦,春花似錦觅闽、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至彻亲,卻和暖如春孕锄,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背苞尝。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評(píng)論 1 270
  • 我被黑心中介騙來泰國(guó)打工畸肆, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人野来。 一個(gè)月前我還...
    沈念sama閱讀 48,158評(píng)論 3 370
  • 正文 我出身青樓恼除,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親曼氛。 傳聞我的和親對(duì)象是個(gè)殘疾皇子豁辉,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,941評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容