linux 跳过delegate_to:www.example.com之后的可能任务127.0.0.1

hgc7kmma  于 2023-01-08  发布在  Linux
关注(0)|答案(1)|浏览(118)

我的代码如下所示,我正在从本地csv文件中阅读这些值,并将其用于远程主机上的任务

---
- name: Empty Topics
  hosts: remote_host
  gather_facts: no
  vars:    
    kafka_topics: /bin/kafka-topics
    bootstrap_server:  "list_of_broker_hosts"
    retention_ms: 604800000
    command_config: /etc/kafka/client.properties
    kafka_log_dirs: /usr/bin/kafka-log-dirs
    #ansible_connection: ssh
    #ansible_user: ansible
    #ansible_become: true
  tasks:
    - name: "Reading Topic Names"
      read_csv:
        path: topics_list.csv
      register: topics
      delegate_to: 127.0.0.1
    - name: "Setting Topic Retention to 0"
      become: yes
      become_user: root
      shell: 
        {{ kafka_topics }} --bootstrap_server {{bootstrap_server}} --alter --topic "{{ item.topic_name }}"  --config retention.ms=0 --command_config #{{command_config}}
        #touch /tmp/producer_test_1
      loop: "{{ topics.list }}"
    - name: "waiting for size to go zero "
      become: yes
      become_user: root
      shell: 
        topic_size=1
        while [ $topic_size -ne 0 ]
        do
          topic_size=`{{kafka_log_dirs}}    --command_config  {{command_config}}   --bootstrap_server {{bootstrap_server}}   --topic-list "{{ item.topic_name }}"   --describe   | grep -oP '(?<=size":)\d+'    | awk '{ sum += $1 } END { print sum }' `
          sleep 40
        done             
      loop: "{{ topics.list }}"
    - name : "Setting Topic Retention to 7"
      become: yes
      become_user: root
      shell: 
         #{{ kafka_topics }} --bootstrap_server {{bootstrap_server}} --alter --topic "{{ item.topic_name }}"  --config retention.ms={{retention_ms}} --command_config {{command_config}}
         #touch /tmp/producer_test_2
      loop: "{{ topics.list }}"

这里跳过了第一个任务“阅读Topic Names”之后的任务,如果我删除此任务,它们会成功,但这意味着我必须在后续任务中硬编码值
执行日志如下。我如何避免这种情况。当前ansible版本是2.9.19此剧本以前在我以前的组织中的ansible版本2.9.6上工作,不确定在我的新公司中可能会更改哪些设置。
我尝试委派_给:本地主机以及委托给:127:0:0:1

ansible@localhost[~] $ ansible-playbook empty_topics.pb  -i /home/ansible/inv_sit.yml  -l all

PLAY [Empty Topics] ***********************************************************************************************************

TASK [Reading Topic Names] ****************************************************************************************************
ok: [remotehost]

TASK [Setting Topic Retention to 0] *******************************************************************************************

TASK [waiting for size to go zero] ********************************************************************************************

TASK [Setting Topic Retention to 7] *******************************************************************************************

PLAY RECAP ********************************************************************************************************************
remotehost : ok=1    changed=0    unreachable=0    failed=0    skipped=3    rescued=0    ignored=0    

ansible@localhost[~] $ ansible-playbook empty_topics.pb  -i /home/ansible/inv_sit.yml  -l all -vvv
ansible-playbook 2.9.19
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible-playbook
  python version = 3.6.8 (default, Jun 14 2022, 12:54:58) [GCC 8.5.0 20210514 (Red Hat 8.5.0-10)]
Using /etc/ansible/ansible.cfg as config file
host_list declined parsing /home/ansible/inv_sit.yml as it did not pass its verify_file() method
script declined parsing /home/ansible/inv_sit.yml as it did not pass its verify_file() method
Parsed /home/ansible/inv_sit.yml inventory source with ini plugin
Skipping callback 'actionable', as we already have a stdout callback.
Skipping callback 'counter_enabled', as we already have a stdout callback.
Skipping callback 'debug', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'dense', as we already have a stdout callback.
Skipping callback 'full_skip', as we already have a stdout callback.
Skipping callback 'json', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'null', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Skipping callback 'selective', as we already have a stdout callback.
Skipping callback 'skippy', as we already have a stdout callback.
Skipping callback 'stderr', as we already have a stdout callback.
Skipping callback 'unixy', as we already have a stdout callback.
Skipping callback 'yaml', as we already have a stdout callback.

PLAYBOOK: empty_topics.pb *****************************************************************************************************
1 plays in empty_topics.pb

PLAY [Empty Topics] ***********************************************************************************************************
META: ran handlers

TASK [Reading Topic Names] ****************************************************************************************************
task path: /home/ansible/empty_topics.pb:18
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: ansible
<127.0.0.1> EXEC /bin/sh -c 'echo ~ansible && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/ansible/.ansible/tmp `"&& mkdir "` echo /home/ansible/.ansibl  e/tmp/ansible-tmp-1672893960.0795922-3957982-94418260356492 `" && echo ansible-tmp-1672893960.0795922-3957982-94418260356492="`   echo /home/ansible/.ansible/tmp/ansible-tmp-1672893960.0795922-3957982-94418260356492 `" ) && sleep 0'
Using module file /usr/lib/python3.6/site-packages/ansible/modules/files/read_csv.py
<127.0.0.1> PUT /home/ansible/.ansible/tmp/ansible-local-3957970ixug96xw/tmpn373dahz TO /home/ansible/.ansible/tmp/ansible-tmp-  1672893960.0795922-3957982-94418260356492/AnsiballZ_read_csv.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/ansible/.ansible/tmp/ansible-tmp-1672893960.0795922-3957982-94418260356492/ /home/  ansible/.ansible/tmp/ansible-tmp-1672893960.0795922-3957982-94418260356492/AnsiballZ_read_csv.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/libexec/platform-python /home/ansible/.ansible/tmp/ansible-tmp-1672893960.0795922-3957982-944  18260356492/AnsiballZ_read_csv.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/ansible/.ansible/tmp/ansible-tmp-1672893960.0795922-3957982-94418260356492/ > /dev/  null 2>&1 && sleep 0'
ok: [remotehost] => {
    "changed": false,
    "dict": {},
    "invocation": {
        "module_args": {
            "delimiter": null,
            "dialect": "excel",
            "fieldnames": null,
            "key": null,
            "path": "topics_list.csv",
            "skipinitialspace": null,
            "strict": null,
            "unique": true
        }
    },
    "list": []
}

TASK [Setting Topic Retention to 0] *******************************************************************************************
task path: /home/ansible/empty_topics.pb:23

TASK [waiting for size to go zero] ********************************************************************************************
task path: /home/ansible/empty_topics.pb:31

TASK [Setting Topic Retention to 7] *******************************************************************************************
task path: /home/ansible/empty_topics.pb:42
META: ran handlers
META: ran handlers

PLAY RECAP ********************************************************************************************************************
remotehost : ok=1    changed=0    unreachable=0    failed=0    skipped=3    rescued=0    ignored=0    

ansible@localhost[~] $

我尝试委派_给:本地主机以及委托给:127:0:0:1

v1l68za4

v1l68za41#

按照β.εηοιτ.βε的建议,我检查了csv文件,虽然有内容,但缺少标题行,因此出现了问题。现在,将标题行添加到csv文件中,代码工作正常。

相关问题