ansible sysctl 模塊

當我們需要修改內(nèi)核參數(shù)時卵迂,可以使用sysctl 模塊。sysctl 可以對值進行設置绒净,如果需要查詢可以使用shell 模塊见咒。

  • name:變量名
  • value:值
  • reload:文件被更新時,是否使用 sysctl -p reload 文件
  • state:是在文件中 移除(absent)或者設置(present)
  • sysctl_file:如果不是默認文件挂疆,指定其他文件
  • sysctl_set:使用sysctl 命令設置改览,不一定需要reload 文件

linux sysctl usage

Usage:
 sysctl [options] [variable[=value] ...]

Options:
  -a, --all            display all variables
  -A                   alias of -a
  -X                   alias of -a
      --deprecated     include deprecated parameters to listing
  -b, --binary         print value without new line
  -e, --ignore         ignore unknown variables errors
  -N, --names          print variable names without values
  -n, --values         print only values of a variables
  -p, --load[=<file>]  read values from file
  -f                   alias of -p
      --system         read values from all system directories
  -r, --pattern <expression>
                       select setting that match expression
  -q, --quiet          do not echo variable set
  -w, --write          enable writing a value to variable
  -o                   does nothing
  -x                   does nothing
  -d                   alias of -h

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see sysctl(8).

ansible-doc sysctl 文檔

> SYSCTL    (/usr/lib/python2.7/site-packages/ansible/modules/system/sysctl.py)

        This module manipulates sysctl entries and optionally performs a `/sbin/sysctl -p' after changing them.

OPTIONS (= is mandatory):

- ignoreerrors
        Use this option to ignore errors about unknown keys.
        (Choices: yes, no)[Default: False]

= name
        The dot-separated path (aka `key') specifying the sysctl variable.
        (Aliases: key)[Default: None]

- reload
        If `yes', performs a `/sbin/sysctl -p' if the `sysctl_file' is updated. If `no', does not reload `sysctl' even if the
        `sysctl_file' is updated.
        (Choices: yes, no)[Default: yes]

- state
        Whether the entry should be present or absent in the sysctl file.
        (Choices: present, absent)[Default: present]

- sysctl_file
        Specifies the absolute path to `sysctl.conf', if not `/etc/sysctl.conf'.
        [Default: /etc/sysctl.conf]

- sysctl_set
        Verify token value with the sysctl command and set with -w if necessary
        (Choices: yes, no)[Default: False]
        version_added: 1.5


- value
        Desired value of the sysctl key.
        (Aliases: val)[Default: None]


AUTHOR: David CHANIAL (@davixx) <david.chanial@gmail.com>
        METADATA:
          status:
          - stableinterface
          supported_by: core

示例

EXAMPLES:
# Set vm.swappiness to 5 in /etc/sysctl.conf
- sysctl:
    name: vm.swappiness
    value: 5
    state: present

# Remove kernel.panic entry from /etc/sysctl.conf
- sysctl:
    name: kernel.panic
    state: absent
    sysctl_file: /etc/sysctl.conf

# Set kernel.panic to 3 in /tmp/test_sysctl.conf
- sysctl:
    name: kernel.panic
    value: 3
    sysctl_file: /tmp/test_sysctl.conf
    reload: no

# Set ip forwarding on in /proc and do not reload the sysctl file
- sysctl:
    name: net.ipv4.ip_forward
    value: 1
    sysctl_set: yes
# Set ip forwarding on in /proc and in the sysctl file and reload if necessary
- sysctl:
    name: net.ipv4.ip_forward
    value: 1
    sysctl_set: yes
    state: present
    reload: yes
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市缤言,隨后出現(xiàn)的幾起案子宝当,更是在濱河造成了極大的恐慌,老刑警劉巖胆萧,帶你破解...
    沈念sama閱讀 221,635評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件庆揩,死亡現(xiàn)場離奇詭異,居然都是意外死亡跌穗,警方通過查閱死者的電腦和手機订晌,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,543評論 3 399
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來瞻离,“玉大人腾仅,你說我怎么就攤上這事√桌” “怎么了推励?”我有些...
    開封第一講書人閱讀 168,083評論 0 360
  • 文/不壞的土叔 我叫張陵,是天一觀的道長肉迫。 經(jīng)常有香客問我验辞,道長,這世上最難降的妖魔是什么喊衫? 我笑而不...
    開封第一講書人閱讀 59,640評論 1 296
  • 正文 為了忘掉前任跌造,我火速辦了婚禮,結(jié)果婚禮上族购,老公的妹妹穿的比我還像新娘壳贪。我一直安慰自己,他們只是感情好寝杖,可當我...
    茶點故事閱讀 68,640評論 6 397
  • 文/花漫 我一把揭開白布违施。 她就那樣靜靜地躺著,像睡著了一般瑟幕。 火紅的嫁衣襯著肌膚如雪磕蒲。 梳的紋絲不亂的頭發(fā)上留潦,一...
    開封第一講書人閱讀 52,262評論 1 308
  • 那天,我揣著相機與錄音辣往,去河邊找鬼兔院。 笑死,一個胖子當著我的面吹牛站削,可吹牛的內(nèi)容都是我干的坊萝。 我是一名探鬼主播,決...
    沈念sama閱讀 40,833評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼钻哩,長吁一口氣:“原來是場噩夢啊……” “哼屹堰!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起街氢,我...
    開封第一講書人閱讀 39,736評論 0 276
  • 序言:老撾萬榮一對情侶失蹤扯键,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后珊肃,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體荣刑,經(jīng)...
    沈念sama閱讀 46,280評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,369評論 3 340
  • 正文 我和宋清朗相戀三年伦乔,在試婚紗的時候發(fā)現(xiàn)自己被綠了厉亏。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,503評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡烈和,死狀恐怖爱只,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情招刹,我是刑警寧澤恬试,帶...
    沈念sama閱讀 36,185評論 5 350
  • 正文 年R本政府宣布,位于F島的核電站疯暑,受9級特大地震影響训柴,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜妇拯,卻給世界環(huán)境...
    茶點故事閱讀 41,870評論 3 333
  • 文/蒙蒙 一幻馁、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧越锈,春花似錦仗嗦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,340評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至对蒲,卻和暖如春钩蚊,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背蹈矮。 一陣腳步聲響...
    開封第一講書人閱讀 33,460評論 1 272
  • 我被黑心中介騙來泰國打工砰逻, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人泛鸟。 一個月前我還...
    沈念sama閱讀 48,909評論 3 376
  • 正文 我出身青樓蝠咆,卻偏偏與公主長得像,于是被迫代替她去往敵國和親北滥。 傳聞我的和親對象是個殘疾皇子刚操,可洞房花燭夜當晚...
    茶點故事閱讀 45,512評論 2 359

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