ãã㯠Ansible 3 Advent Calendar 2019 ã®6æ¥ç®ã®è¨äºã§ããï¼ããã®ã¼ãæ稿ï¼
â ã¯ããã«
å½ã¢ããã³ãã«ã¬ã³ãã¼ã® 5æ¥ç®ã®è¨äºã¯ãæ¢åã® 0,1 ãæ¸ããã¦ãããã¡ã¤ã«ãå転ããã¦å¥ã®ãã¡ã¤ã«ãçæããã¨ããè¨äºã§ããã
ããããå¥è§£ãèãã¦ã¿ãããã¿ã§ããæ¯é :)ãã¨ã®ãã¨ã ã£ãã®ã§èãã¾ããã
â 使ç¨ãããã¡ã¤ã«
å ã®è¨äºã¨åããã¡ã¤ã«ãç¨æãããã¾ãã
$ cat before_number.txt 001010101010101010010101 111000101010100111010011 100001010100001010101010 110101010101010010101010 101010100101010101010000 111111100000111010000000
â Playbook
å¦çã®æ¦è¦ã¯ä»¥ä¸ã®ã¨ããã§ãã
- ã¨ããããã
copy ã¢ã¸ã¥ã¼ã«
ã§ãã¡ã¤ã«ããã®ã¾ã¾ã³ãã¼ replace
ã¢ã¸ã¥ã¼ã« ã§0
ãx
ã«ã1
ãy
ã«ç½®æreplace
ã¢ã¸ã¥ã¼ã« ã§x
ã1
ã«ãy
ã0
ã«ç½®æ
Playbook ã¯ä»¥ä¸ã®ã¨ããã§ãã
- main.yml
- hosts: localhost connection: local gather_facts: no tasks: # ã¾ããã®ã¾ã¾ã³ãã¼ - name: copy copy: src: before_number.txt dest: after_number.txt # 0 㨠1 ãããããä»®ã®æåã«ç½®æ - name: replace to temporary chars replace: path: after_number.txt regexp: "{{ item.regexp }}" replace: "{{ item.replace }}" loop: - regexp: 0 replace: "x" - regexp: 1 replace: "y" # True ã«ãªããªãããã«ã¯ã©ã¼ãã¼ã·ã§ã³ãå¿ è¦ # ä»®ã®æåãå転ãã 0/1ã«ç½®æ - name: replace to 0/1 replace: path: after_number.txt regexp: "{{ item.regexp }}" replace: "{{ item.replace }}" loop: - regexp: "x" # ãã¨ã㨠0 ã ã£ãã¨ãã replace: 1 # 1 ã«ç½®æ - regexp: "y" # ãã¨ã㨠1 ã ã£ãã¨ãã replace: 0 # 0 ã«ç½®æ
â Playbookå®è¡
Playbook ãå®è¡ãã¾ã
$ ansible-playbook -i localhost, main.yml PLAY [localhost] ************************************************************************************************** TASK [copy] ******************************************************************************************************* changed: [localhost] TASK [replace to temporary chars] ********************************************************************************* changed: [localhost] => (item={'regexp': 0, 'replace': 'x'}) changed: [localhost] => (item={'regexp': 1, 'replace': 'y'}) TASK [replace to 0/1] ********************************************************************************************* changed: [localhost] => (item={'regexp': 'x', 'replace': 1}) changed: [localhost] => (item={'regexp': 'y', 'replace': 0}) PLAY RECAP ******************************************************************************************************** localhost : ok=3 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 $
ä½æããããã¡ã¤ã«ã®ä¸èº«ãè¦ã¦ã¿ã¾ãã
$ cat after_number.txt 110101010101010101101010 000111010101011000101100 011110101011110101010101 001010101010101101010101 010101011010101010101111 000000011111000101111111
ç¡äºã« before_number.txt
㨠0,1 ãå転ãããã¡ã¤ã«ãçæããã¾ããã
ãã¾ãçã§ãããafter_number.txt
ã®å
容ãæ¸ãæãã£ã¦ããæ§åã®ã§ãã
0/1 ãå転ãããã¡ã¤ã«ãçæããæ§å pic.twitter.com/vJ3A6tnBgp
— ããã¡(yokochi) @ Ansibleå®è·µã¬ã¤ã 第3ç (@akira6592) 2019å¹´12æ14æ¥
â ãã®ä»èãããã¨
ãã®æ¹æ³ã«è³ãã¾ã§ã«èãããã¨ã§ãã
- ãã£ãã2é²æ°ãªã®ã§ãPythonã® ãããå転ã®
~
ã使ãããè¯ããªã¨æã£ããã©ããã¾ã çµã¿è¾¼ããªãã£ã - replace ã¢ã¸ã¥ã¼ã«ã使ã£ã¦ã¿ãã
0
ã1
ã«ã1
ã0
ã«ãã£ãºãã«ç½®æã§ããã°ãããã©ãã§ããªãããã- ï¼
ternay
ãã£ã«ã¿ã¼ã使ãã°ã§ããã ãããã»ã»ï¼ - 2段éã®ç½®æã§ã©ãã«ãã§ãã
- ãã ããã®æ¹æ³ã ã¨åªçæ§ããªããæ¯å
changed
ã«ãªã£ã¦ãã¾ã - ä¸éãã¡ã¤ã«ã®çæå¦çãæãã°ã§ããããªãã¾ããããã