0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ansible学習中

Last updated at Posted at 2025-07-20

事前にインベントリファイルに変数を記載

[root@docker163 ansible]# cat inventory.ini
[mqservers]
mq1
mq2
mq3
[mqservers:vars]
ansible_home=/work

ファイルコピープレイブック

[root@docker163 ansible]# cat test.yml
---
- hosts: mqservers
  become: yes
  tasks:

    - debug:
        msg: "{{ ansible_home }}"


    - name: Copy job
      ansible.builtin.copy:
       src: "zzz.txt"
       dest: "{{ansible_home}}/"
       mode: 0775

ファイル削除プレイブック

[root@docker163 ansible]# cat rmfile.yml
---
- hosts: mqservers
  become: yes
  tasks:
    - name: rm file job
      ansible.builtin.file:
       path: "{{ ansible_home }}"/zzz.txt"
       state: absent

lsしてやれ

---
- hosts: mqservers
  become: yes
  tasks:

    - name: xxx
      shell: 'grep mail /etc/passwd | cut -d: -f6'
      register: hensu

    - name: yyy
      set_fact: lsdir='{{ hensu.stdout }}'

    - name: xxxe
      shell: 'ls "{{ lsdir }}" '
      register: kekka

    - debug:
       msg: "{{ kekka }}"

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?